New:Socket for Asana Is Now Available.Learn more
Get Started

@x402/evm

Package Overview
Dependencies
Maintainers
2
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@x402/evm - npm Package Compare versions

Comparing version
2.21.0
to
2.22.0
+307
dist/cjs/scheme-C41SfdnU.d.ts
import { PaymentRequirements, SettleResponse, SchemeNetworkClient, SchemeClientHooks, PaymentPayloadContext, PaymentPayloadResult, PaymentRequired } from '@x402/core/types';
import { C as ClientEvmSigner } from './signer-B127taDR.js';
import { C as ChannelConfig } from './types-B4ib_1f_.js';
import { c as EvmSchemeOptions } from './rpc-DULZzRne.js';
import { B as BatchSettlementClientContext, C as ClientChannelStorage } from './storage-BFpn16ZW.js';
/**
* Caller-tunable policy controlling how the client sizes channel deposits.
*/
interface BatchSettlementDepositPolicy {
depositMultiplier?: number;
}
/**
* Return shape for custom deposit sizing.
*/
type BatchSettlementDepositStrategyResult = string | bigint | false | undefined;
/**
* Information supplied before the client signs a deposit authorization.
*/
interface BatchSettlementDepositStrategyContext {
paymentRequirements: PaymentRequirements;
channelConfig: ChannelConfig;
channelId: `0x${string}`;
clientContext: BatchSettlementClientContext;
requestAmount: string;
maxClaimableAmount: string;
currentBalance: string;
minimumDepositAmount: string;
depositAmount: string;
}
/**
* Custom deposit sizing callback for initial deposits and top-ups.
*/
type BatchSettlementDepositStrategy = (context: BatchSettlementDepositStrategyContext) => BatchSettlementDepositStrategyResult | Promise<BatchSettlementDepositStrategyResult>;
/**
* Full options object accepted by `BatchSettlementEvmScheme`. Either this or a
* bare {@link BatchSettlementDepositPolicy} can be passed as the second
* constructor argument.
*/
interface BatchSettlementEvmSchemeOptions {
depositPolicy?: BatchSettlementDepositPolicy;
/** Optional callback for app-specific deposit sizing or skipping. */
depositStrategy?: BatchSettlementDepositStrategy;
storage?: ClientChannelStorage;
salt?: `0x${string}`;
payerAuthorizer?: `0x${string}`;
rpcUrl?: string;
/** When set, EIP-712 vouchers are signed with this key; deposits still use the main `signer`. */
voucherSigner?: ClientEvmSigner;
}
/**
* Resolved options after merging defaults — used internally by the scheme,
* recovery, and refund modules.
*/
interface ResolvedClientOptions {
depositPolicy?: BatchSettlementDepositPolicy;
depositStrategy?: BatchSettlementDepositStrategy;
storage: ClientChannelStorage;
salt: `0x${string}`;
payerAuthorizer?: `0x${string}`;
voucherSigner?: ClientEvmSigner;
extensionRpcOptions?: EvmSchemeOptions;
}
/**
* Discriminates a full options object from a bare deposit-policy object.
*
* @param o - Constructor argument that may be options, deposit policy only, or undefined.
* @returns `true` when `o` is a {@link BatchSettlementEvmSchemeOptions} object.
*/
declare function isBatchSettlementEvmSchemeOptions(o: BatchSettlementEvmSchemeOptions | BatchSettlementDepositPolicy | undefined): o is BatchSettlementEvmSchemeOptions;
/**
* Normalises the constructor's second argument into a uniform options shape.
*
* @param second - Optional second constructor argument (options or deposit policy).
* @returns Resolved storage, salt, deposit policy, and optional payer authorizer.
*/
declare function resolveClientOptions(second?: BatchSettlementEvmSchemeOptions | BatchSettlementDepositPolicy): ResolvedClientOptions;
/**
* Validates a {@link BatchSettlementDepositPolicy}, throwing on invalid fields.
*
* @param policy - The policy to validate (no-op when undefined).
*/
declare function validateDepositPolicy(policy: BatchSettlementDepositPolicy | undefined): void;
/**
* Computes the deposit amount based on the deposit multiplier.
*
* @param policy - Deposit policy controlling multiplier (may be undefined).
* @param requestAmount - Amount requested for this operation, in token base units.
* @returns Deposit amount string in token base units.
*/
declare function depositAmountForRequest(policy: BatchSettlementDepositPolicy | undefined, requestAmount: bigint): string;
/**
* Runtime dependency bag shared by every storage-bound client helper (channel,
* recovery, refund) and the {@link BatchSettlementEvmScheme} class.
*/
interface BatchSettlementClientDeps {
signer: ClientEvmSigner;
storage: ClientChannelStorage;
salt: `0x${string}`;
payerAuthorizer?: `0x${string}`;
voucherSigner?: ClientEvmSigner;
}
/**
* Constructs the immutable {@link ChannelConfig} from payment requirements and
* a client deps bag (signer, salt, optional payerAuthorizer / voucherSigner).
*
* @param deps - Client identity inputs.
* @param paymentRequirements - Server payment requirements providing receiver, asset, and extra fields.
* @returns The ChannelConfig that uniquely identifies this payment channel.
*/
declare function buildChannelConfig(deps: BatchSettlementClientDeps, paymentRequirements: PaymentRequirements): ChannelConfig;
/**
* Updates local channel state from a parsed `SettleResponse`.
*
* @param storage - Client channel storage.
* @param settle - The parsed settle response.
*/
declare function processSettleResponse(storage: ClientChannelStorage, settle: SettleResponse): Promise<void>;
/**
* Reconciles local channel state with the outcome of a cooperative refund.
*
* Deletes the channel record when the post-refund balance is zero (full refund),
* otherwise updates local state from the server snapshot.
*
* @param storage - Client channel storage.
* @param channelKey - Lowercased channel id used as the storage key.
* @param settleExtra - The `extra` block from the refund settle response.
*/
declare function updateChannelAfterRefund(storage: ClientChannelStorage, channelKey: string, settleExtra: Record<string, unknown>): Promise<void>;
/**
* Processes the `PAYMENT-RESPONSE` header after a successful request.
*
* Decodes the header into a `SettleResponse` and delegates to
* {@link processSettleResponse}.
*
* @param storage - Client channel storage.
* @param getHeader - Function to retrieve a response header by name.
*/
declare function processPaymentResponse(storage: ClientChannelStorage, getHeader: (name: string) => string | null | undefined): Promise<void>;
/**
* Recovers a channel record from onchain state (useful after a cold start or
* channel record loss).
*
* @param deps - Signer + storage + identity inputs.
* @param paymentRequirements - Server payment requirements used to derive the ChannelConfig.
* @returns The recovered client context.
*/
declare function recoverChannel(deps: BatchSettlementClientDeps, paymentRequirements: PaymentRequirements): Promise<BatchSettlementClientContext>;
/**
* Reads `channels(channelId)` returning `[balance, totalClaimed]`.
*
* @param signer - Signer providing `readContract`.
* @param channelId - The `bytes32` channel id to query.
* @returns Tuple of `[balance, totalClaimed]` as bigints.
*/
declare function readChannelBalanceAndTotalClaimed(signer: ClientEvmSigner, channelId: `0x${string}`): Promise<[bigint, bigint]>;
/**
* Returns whether a local channel record exists for the given channel.
*
* @param storage - Client channel storage.
* @param channelId - The channel identifier to check.
* @returns `true` when a channel record is stored.
*/
declare function hasChannel(storage: ClientChannelStorage, channelId: string): Promise<boolean>;
/**
* Returns the local channel context for a channel, if present.
*
* @param storage - Client channel storage.
* @param channelId - The channel identifier.
* @returns Stored context or `undefined`.
*/
declare function getChannel(storage: ClientChannelStorage, channelId: string): Promise<BatchSettlementClientContext | undefined>;
/**
* Caller-facing options for {@link refundChannel}.
*/
interface RefundOptions {
/** Token base units to refund; omit for a full refund (drains remaining balance). */
amount?: string;
/** Custom fetch implementation (defaults to `globalThis.fetch`). */
fetch?: typeof fetch;
}
/**
* Sends a cooperative refund request to the channel that backs `url`.
*
* Flow:
* 1. Probe the URL with `GET` (no payment) to obtain the route's payment requirements.
* 2. Build the `ChannelConfig` and resolve the local session (or recover it).
* 3. Sign a zero-charge refund voucher (`maxClaimableAmount = chargedCumulativeAmount`).
* 4. Send the voucher via `PAYMENT-SIGNATURE`. On a corrective 402, run the
* standard recovery path and retry once.
* 5. Return the parsed `SettleResponse` from the server.
*
* @param ctx - Identity inputs (storage, signers, salt, payerAuthorizer).
* @param url - Any protected route on the channel to refund (the resource handler is bypassed).
* @param options - Optional `amount` (partial refund) and `fetch` override.
* @returns The settle response describing the refund outcome.
* @throws When the probe fails, the receiver lacks an authorizer, or recovery fails.
*/
declare function refundChannel(ctx: BatchSettlementClientDeps, url: string, options?: RefundOptions): Promise<SettleResponse>;
/**
* Client-side implementation of the `batch-settlement` scheme for EVM networks.
*
* Builds payment payloads (deposit + voucher or voucher-only), processes server
* responses to update local session state via {@link processSettleResponse},
* handles corrective 402 resynchronisation via
* {@link processCorrectivePaymentRequired}, and supports on-demand cooperative
* refund requests via {@link refundChannel}.
*/
declare class BatchSettlementEvmScheme implements SchemeNetworkClient {
private readonly signer;
readonly scheme: "batch-settlement";
readonly schemeHooks: SchemeClientHooks;
private readonly storage;
private readonly depositPolicy;
private readonly depositStrategy;
private readonly salt;
private readonly payerAuthorizer;
private readonly voucherSigner;
private readonly extensionRpcOptions;
/**
* Constructs a batched client scheme.
*
* @param signer - Client EVM wallet used for signing vouchers and ERC-3009 authorizations.
* @param optionsOrPolicy - Either a full options object or a bare deposit-policy.
*/
constructor(signer: ClientEvmSigner, optionsOrPolicy?: BatchSettlementEvmSchemeOptions | BatchSettlementDepositPolicy);
/**
* Creates the payment payload for a batched request.
*
* If the channel has no onchain deposit (or needs a top-up), builds an
* ERC-3009 deposit payload bundled with a voucher. Otherwise, signs and
* returns a voucher-only payload.
*
* @param x402Version - Protocol version for the payload envelope.
* @param paymentRequirements - Server payment requirements (scheme, network, asset, amount).
* @param context - Optional payment payload context with extension hints.
* @returns A {@link PaymentPayloadResult} ready to be sent as the `X-PAYMENT` header.
*/
createPaymentPayload(x402Version: number, paymentRequirements: PaymentRequirements, context?: PaymentPayloadContext): Promise<PaymentPayloadResult>;
/**
* Sends a cooperative refund request.
*
* @param url - The route URL backing the channel to refund.
* @param options - Optional `amount` (partial refund) and `fetch` override.
* @returns The settle response describing the refund outcome.
*/
refund(url: string, options?: RefundOptions): Promise<SettleResponse>;
/**
* Updates local channel state from a settle response.
*
* @param settle - The parsed settle response from the server.
* @returns Resolves when local channel state has been updated.
*/
processSettleResponse(settle: SettleResponse): Promise<void>;
/**
* Resyncs local channel state from a corrective 402 response.
*
* @param paymentRequired - The decoded 402 response body.
* @returns `true` if local state was successfully resynced and a retry is warranted.
*/
processCorrectivePaymentRequired(paymentRequired: PaymentRequired): Promise<boolean>;
/**
* Builds the immutable {@link ChannelConfig} for a given set of payment
* requirements, using the scheme's own signer and salt.
*
* @param paymentRequirements - Server payment requirements for the channel.
* @returns The channel config that uniquely identifies the payment channel.
*/
buildChannelConfig(paymentRequirements: PaymentRequirements): ChannelConfig;
/**
* Resolves the deposit amount after applying the optional custom strategy.
*
* @param context - Deposit attempt context exposed to the strategy.
* @returns The deposit amount to sign, or `false` to skip this deposit attempt.
*/
private resolveDepositAmount;
/**
* Normalizes and validates a strategy-provided base-unit deposit amount.
*
* @param value - Strategy-provided string or bigint amount.
* @returns Normalized decimal string.
*/
private normalizeStrategyDepositAmount;
/**
* Signs a voucher-only payment payload for the current channel.
*
* @param x402Version - Protocol version for the payload envelope.
* @param channelId - Channel identifier for the voucher.
* @param maxClaimableAmount - Cumulative ceiling for the voucher.
* @param network - CAIP-2 network identifier.
* @param config - Immutable channel configuration.
* @returns Voucher-only payment payload.
*/
private createVoucherPayload;
/**
* Bundles the class state into the {@link BatchSettlementClientDeps} shape
* consumed by the `channel`, `recovery`, and `refund` modules.
*
* @returns Client deps wrapping the scheme's own signer and storage.
*/
private deps;
}
export { type BatchSettlementClientDeps as B, type RefundOptions as R, BatchSettlementEvmScheme as a, type BatchSettlementDepositPolicy as b, type BatchSettlementDepositStrategy as c, type BatchSettlementDepositStrategyContext as d, type BatchSettlementDepositStrategyResult as e, type BatchSettlementEvmSchemeOptions as f, depositAmountForRequest as g, resolveClientOptions as h, isBatchSettlementEvmSchemeOptions as i, type ResolvedClientOptions as j, buildChannelConfig as k, getChannel as l, hasChannel as m, processSettleResponse as n, readChannelBalanceAndTotalClaimed as o, processPaymentResponse as p, recoverChannel as q, refundChannel as r, updateChannelAfterRefund as u, validateDepositPolicy as v };
import { C as ChannelConfig } from './types-B4ib_1f_.js';
interface Channel {
channelId: string;
channelConfig: ChannelConfig;
chargedCumulativeAmount: string;
signedMaxClaimable: string;
signature: string;
balance: string;
totalClaimed: string;
withdrawRequestedAt: number;
refundNonce: number;
onchainSyncedAt?: number;
lastRequestTimestamp: number;
pendingRequest?: PendingRequest;
}
interface PendingRequest {
pendingId: string;
signedMaxClaimable: string;
expiresAt: number;
}
interface ChannelUpdateResult {
channel: Channel | undefined;
status: "updated" | "unchanged" | "deleted";
}
interface ChannelStorage {
get(channelId: string): Promise<Channel | undefined>;
list(): Promise<Channel[]>;
/**
* Atomically inspects and mutates a channel record.
*
* Implementations must guarantee that no concurrent mutation can interleave between
* reading `current` and writing the callback result for all application instances that
* share the backend. The in-memory backend only provides this guarantee inside one JS
* runtime; production multi-instance deployments need storage with backend-level atomic
* conditional mutation, such as Redis/Valkey Lua scripts, SQL transactions, or Durable Objects.
*
* @param channelId - The channel identifier.
* @param update - Mutation callback. Return `undefined` to delete, or `current` to leave unchanged.
* @returns The final stored channel and whether storage updated, stayed unchanged, or deleted.
*/
updateChannel(channelId: string, update: (current: Channel | undefined) => Channel | undefined): Promise<ChannelUpdateResult>;
}
/**
* In-memory {@link ChannelStorage} backed by a Map keyed by `channelId`.
*/
declare class InMemoryChannelStorage implements ChannelStorage {
private readonly channels;
private readonly channelLocks;
/**
* Returns the channel record for a channel, if present.
*
* @param channelId - The channel identifier.
* @returns The channel record or undefined when not found.
*/
get(channelId: string): Promise<Channel | undefined>;
/**
* Lists all stored channel records.
*
* @returns All channel records in storage.
*/
list(): Promise<Channel[]>;
/**
* Atomically inspects and mutates a channel record while holding a per-channel lock.
*
* @param channelId - The channel identifier.
* @param update - Mutation callback. Return `undefined` to delete, or `current` to leave unchanged.
* @returns The final stored channel and whether storage updated, stayed unchanged, or deleted.
*/
updateChannel(channelId: string, update: (current: Channel | undefined) => Channel | undefined): Promise<ChannelUpdateResult>;
/**
* Runs `fn` after any prior locked work for the same channel key has finished.
*
* @param key - Lowercased channel id used as the lock key.
* @param fn - Async work to run while holding the logical per-channel lock.
* @returns The resolved result of `fn`.
*/
private withChannelLock;
}
export { type ChannelStorage as C, InMemoryChannelStorage as I, type PendingRequest as P, type Channel as a, type ChannelUpdateResult as b };
import { TypedData } from 'viem';
interface AuthorizerSigner {
address: `0x${string}`;
signTypedData(params: {
domain: Record<string, unknown>;
types: TypedData;
primaryType: string;
message: Record<string, unknown>;
}): Promise<`0x${string}`>;
}
type ChannelState = {
balance: bigint;
totalClaimed: bigint;
withdrawRequestedAt: number;
refundNonce: bigint;
};
type ChannelConfig = {
payer: `0x${string}`;
payerAuthorizer: `0x${string}`;
receiver: `0x${string}`;
receiverAuthorizer: `0x${string}`;
token: `0x${string}`;
withdrawDelay: number;
salt: `0x${string}`;
};
type BatchSettlementErc3009Authorization = {
validAfter: string;
validBefore: string;
salt: `0x${string}`;
signature: `0x${string}`;
};
type BatchSettlementPermit2Authorization = {
from: `0x${string}`;
permitted: {
token: `0x${string}`;
amount: string;
};
spender: `0x${string}`;
nonce: string;
deadline: string;
witness: {
channelId: `0x${string}`;
};
signature: `0x${string}`;
};
type BatchSettlementAssetTransferMethod = "eip3009" | "permit2";
type BatchSettlementDepositAuthorization = {
erc3009Authorization: BatchSettlementErc3009Authorization;
permit2Authorization?: never;
} | {
erc3009Authorization?: never;
permit2Authorization: BatchSettlementPermit2Authorization;
};
type BatchSettlementDepositPayload = {
type: "deposit";
channelConfig: ChannelConfig;
voucher: BatchSettlementVoucherFields;
deposit: {
amount: string;
authorization: BatchSettlementDepositAuthorization;
};
};
type BatchSettlementVoucherPayload = {
type: "voucher";
channelConfig: ChannelConfig;
voucher: BatchSettlementVoucherFields;
};
type BatchSettlementRefundPayload = {
type: "refund";
channelConfig: ChannelConfig;
voucher: BatchSettlementVoucherFields;
amount?: string;
};
type BatchSettlementVoucherFields = {
channelId: `0x${string}`;
maxClaimableAmount: string;
signature: `0x${string}`;
};
type BatchSettlementVoucherClaim = {
voucher: {
channel: ChannelConfig;
maxClaimableAmount: string;
};
signature: `0x${string}`;
totalClaimed: string;
};
type BatchSettlementChannelStateExtra = {
channelId: `0x${string}`;
balance: string;
totalClaimed: string;
withdrawRequestedAt: number;
refundNonce: string;
chargedCumulativeAmount?: string;
};
type BatchSettlementVoucherStateExtra = {
signedMaxClaimable?: string;
signature?: `0x${string}`;
};
type BatchSettlementPaymentRequirementsExtra = {
receiverAuthorizer: `0x${string}`;
withdrawDelay: number;
name: string;
version: string;
assetTransferMethod?: BatchSettlementAssetTransferMethod;
channelState?: BatchSettlementChannelStateExtra;
voucherState?: BatchSettlementVoucherStateExtra;
};
type FileChannelStorageOptions = {
/** Root directory; channels are stored under `{directory}/{client|server}/{channelId}.json`. */
directory: string;
};
type BatchSettlementPaymentResponseExtra = {
chargedAmount?: string;
channelState?: BatchSettlementChannelStateExtra;
voucherState?: BatchSettlementVoucherStateExtra;
};
type BatchSettlementClaimPayload = {
type: "claim";
claims: BatchSettlementVoucherClaim[];
claimAuthorizerSignature?: `0x${string}`;
};
type BatchSettlementSettlePayload = {
type: "settle";
receiver: `0x${string}`;
token: `0x${string}`;
};
type BatchSettlementEnrichedRefundPayload = BatchSettlementRefundPayload & {
amount: string;
refundNonce: string;
claims: BatchSettlementVoucherClaim[];
refundAuthorizerSignature?: `0x${string}`;
claimAuthorizerSignature?: `0x${string}`;
};
type BatchSettlementPayload = BatchSettlementDepositPayload | BatchSettlementVoucherPayload | BatchSettlementRefundPayload;
type BatchSettlementFacilitatorSettlePayload = BatchSettlementDepositPayload | BatchSettlementClaimPayload | BatchSettlementSettlePayload | BatchSettlementEnrichedRefundPayload;
/**
* Type guard for {@link BatchSettlementDepositPayload}.
*
* @param payload - Unknown payload to check.
* @returns True if `payload` is a deposit payload (carries `deposit` and `voucher`).
*/
declare function isBatchSettlementDepositPayload(payload: unknown): payload is BatchSettlementDepositPayload;
/**
* Type guard for {@link BatchSettlementVoucherPayload}.
*
* @param payload - Unknown payload to check.
* @returns True if `payload` is a voucher payload with channel and signature fields.
*/
declare function isBatchSettlementVoucherPayload(payload: unknown): payload is BatchSettlementVoucherPayload;
/**
* Type guard for {@link BatchSettlementRefundPayload}.
*
* @param payload - Unknown payload to check.
* @returns True if `payload` is a refund payload with channel config and voucher fields.
*/
declare function isBatchSettlementRefundPayload(payload: unknown): payload is BatchSettlementRefundPayload;
/**
* Type guard for {@link BatchSettlementClaimPayload}.
*
* @param payload - Unknown payload to check.
* @returns True if `payload` is a settle-action `claimWithSignature` payload.
*/
declare function isBatchSettlementClaimPayload(payload: unknown): payload is BatchSettlementClaimPayload;
/**
* Type guard for {@link BatchSettlementSettlePayload}.
*
* @param payload - Unknown payload to check.
* @returns True if `payload` is a settle-action `settle` payload.
*/
declare function isBatchSettlementSettlePayload(payload: unknown): payload is BatchSettlementSettlePayload;
/**
* Type guard for {@link BatchSettlementEnrichedRefundPayload}.
*
* @param payload - Unknown payload to check.
* @returns True if `payload` is a settle-action `refundWithSignature` payload.
*/
declare function isBatchSettlementEnrichedRefundPayload(payload: unknown): payload is BatchSettlementEnrichedRefundPayload;
export { type AuthorizerSigner as A, type BatchSettlementVoucherClaim as B, type ChannelConfig as C, type FileChannelStorageOptions as F, type BatchSettlementAssetTransferMethod as a, type BatchSettlementVoucherFields as b, type BatchSettlementChannelStateExtra as c, type BatchSettlementVoucherStateExtra as d, type ChannelState as e, type BatchSettlementDepositPayload as f, type BatchSettlementVoucherPayload as g, type BatchSettlementRefundPayload as h, type BatchSettlementErc3009Authorization as i, type BatchSettlementClaimPayload as j, type BatchSettlementEnrichedRefundPayload as k, type BatchSettlementPayload as l, type BatchSettlementSettlePayload as m, type BatchSettlementFacilitatorSettlePayload as n, type BatchSettlementPaymentRequirementsExtra as o, type BatchSettlementPaymentResponseExtra as p, isBatchSettlementDepositPayload as q, isBatchSettlementVoucherPayload as r, isBatchSettlementRefundPayload as s, isBatchSettlementClaimPayload as t, isBatchSettlementSettlePayload as u, isBatchSettlementEnrichedRefundPayload as v };
/**
* Asset transfer methods for the exact EVM scheme.
* - eip3009: Uses transferWithAuthorization (USDC, etc.) - recommended for compatible tokens
* - permit2: Uses Permit2 + x402Permit2Proxy - universal fallback for any ERC-20
*/
type AssetTransferMethod = "eip3009" | "permit2";
/**
* EIP-3009 payload for tokens with native transferWithAuthorization support.
*/
type ExactEIP3009Payload = {
signature?: `0x${string}`;
authorization: {
from: `0x${string}`;
to: `0x${string}`;
value: string;
validAfter: string;
validBefore: string;
nonce: `0x${string}`;
};
};
/**
* Permit2 witness data structure.
* Matches the Witness struct in x402Permit2Proxy contract.
* Note: Upper time bound is enforced by Permit2's `deadline` field, not a witness field.
*/
type Permit2Witness = {
to: `0x${string}`;
validAfter: string;
};
/**
* Permit2 authorization parameters.
* Used to reconstruct the signed message for verification.
*/
type Permit2Authorization = {
permitted: {
token: `0x${string}`;
amount: string;
};
spender: `0x${string}`;
nonce: string;
deadline: string;
witness: Permit2Witness;
};
/**
* Permit2 payload for tokens using the Permit2 + x402Permit2Proxy flow.
*/
type ExactPermit2Payload = {
signature: `0x${string}`;
permit2Authorization: Permit2Authorization & {
from: `0x${string}`;
};
};
type ExactEvmPayloadV1 = ExactEIP3009Payload;
type ExactEvmPayloadV2 = ExactEIP3009Payload | ExactPermit2Payload;
/**
* Type guard to check if a payload is a Permit2 payload.
* Permit2 payloads have a `permit2Authorization` field.
*
* @param payload - The payload to check.
* @returns True if the payload is a Permit2 payload, false otherwise.
*/
declare function isPermit2Payload(payload: ExactEvmPayloadV2): payload is ExactPermit2Payload;
/**
* Type guard to check if a payload is an EIP-3009 payload.
* EIP-3009 payloads have an `authorization` field.
*
* @param payload - The payload to check.
* @returns True if the payload is an EIP-3009 payload, false otherwise.
*/
declare function isEIP3009Payload(payload: ExactEvmPayloadV2): payload is ExactEIP3009Payload;
/**
* Upto Permit2 witness — includes `facilitator` field absent from exact witness.
* Only the address matching `witness.facilitator` can call settle() on-chain.
*/
type UptoPermit2Witness = {
to: `0x${string}`;
facilitator: `0x${string}`;
validAfter: string;
};
type UptoPermit2Authorization = {
permitted: {
token: `0x${string}`;
amount: string;
};
spender: `0x${string}`;
nonce: string;
deadline: string;
witness: UptoPermit2Witness;
};
type UptoPermit2Payload = {
signature: `0x${string}`;
permit2Authorization: UptoPermit2Authorization & {
from: `0x${string}`;
};
};
/**
* Type guard to check if a payload is an upto Permit2 payload.
* Validates structural presence of all required fields: signature, permit2Authorization
* (with from, permitted, spender, nonce, deadline), and a witness containing facilitator.
*
* @param payload - The payload to check.
* @returns True if the payload is an upto Permit2 payload, false otherwise.
*/
declare function isUptoPermit2Payload(payload: Record<string, unknown>): payload is UptoPermit2Payload;
export { type AssetTransferMethod as A, type ExactEIP3009Payload as E, type Permit2Witness as P, type UptoPermit2Payload as U, type ExactPermit2Payload as a, type ExactEvmPayloadV1 as b, type ExactEvmPayloadV2 as c, type Permit2Authorization as d, isEIP3009Payload as e, type UptoPermit2Witness as f, type UptoPermit2Authorization as g, isUptoPermit2Payload as h, isPermit2Payload as i };
// src/shared/defaultAssets.ts
var DEFAULT_STABLECOINS = {
"eip155:8453": {
address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
name: "USD Coin",
version: "2",
decimals: 6
},
// Base mainnet USDC
"eip155:84532": {
address: "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
name: "USDC",
version: "2",
decimals: 6
},
// Base Sepolia USDC
"eip155:4326": {
address: "0xFAfDdbb3FC7688494971a79cc65DCa3EF82079E7",
name: "MegaUSD",
version: "1",
decimals: 18,
assetTransferMethod: "permit2",
supportsEip2612: true
},
// MegaETH mainnet MegaUSD (no EIP-3009, supports EIP-2612)
"eip155:143": {
address: "0x754704Bc059F8C67012fEd69BC8A327a5aafb603",
name: "USDC",
version: "2",
decimals: 6
},
// Monad mainnet USDC
"eip155:988": {
address: "0x779Ded0c9e1022225f8E0630b35a9b54bE713736",
name: "USDT0",
version: "1",
decimals: 6
},
// Stable mainnet USDT0
"eip155:2201": {
address: "0x78Cf24370174180738C5B8E352B6D14c83a6c9A9",
name: "USDT0",
version: "1",
decimals: 6
},
// Stable testnet USDT0
"eip155:137": {
address: "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",
name: "USD Coin",
version: "2",
decimals: 6
},
// Polygon mainnet USDC
"eip155:42161": {
address: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
name: "USD Coin",
version: "2",
decimals: 6
},
// Arbitrum One USDC
"eip155:421614": {
address: "0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d",
name: "USD Coin",
version: "2",
decimals: 6
},
// Arbitrum Sepolia USDC
"eip155:31612": {
address: "0xdD468A1DDc392dcdbEf6db6e34E89AA338F9F186",
name: "Mezo USD",
version: "1",
decimals: 18,
assetTransferMethod: "permit2",
supportsEip2612: true
},
// Mezo mainnet mUSD (no EIP-3009, supports EIP-2612)
"eip155:31611": {
address: "0x118917a40FAF1CD7a13dB0Ef56C86De7973Ac503",
name: "Mezo USD",
version: "1",
decimals: 18,
assetTransferMethod: "permit2",
supportsEip2612: true
},
// Mezo Testnet mUSD (no EIP-3009, supports EIP-2612)
"eip155:723487": {
address: "0x33ad9e4BD16B69B5BFdED37D8B5D9fF9aba014Fb",
name: "Stable Coin",
version: "1",
decimals: 6,
assetTransferMethod: "permit2",
supportsEip2612: true
},
// Radius Network SBC (no EIP-3009, supports EIP-2612)
"eip155:72344": {
address: "0x33ad9e4BD16B69B5BFdED37D8B5D9fF9aba014Fb",
name: "Stable Coin",
version: "1",
decimals: 6,
assetTransferMethod: "permit2",
supportsEip2612: true
},
// Radius Testnet SBC (no EIP-3009, supports EIP-2612)
"eip155:36900": {
address: "0x9cb8142aEBBcdc60AF7c97Af897A67A8f3CA71C2",
name: "USDC.e",
version: "2",
decimals: 6
},
// ADI Chain USDC.e (EIP-3009 supported)
"eip155:190415": {
address: "0x401eCb1D350407f13ba348573E5630B83638E30D",
name: "Bridged USDC",
version: "2",
decimals: 6
},
// HPP mainnet USDC.e
"eip155:181228": {
address: "0x401eCb1D350407f13ba348573E5630B83638E30D",
name: "Bridged USDC",
version: "2",
decimals: 6
},
// HPP Sepolia USDC.e
"eip155:50": {
address: "0xfA2958CB79b0491CC627c1557F441eF849Ca8eb1",
name: "USDC",
version: "2",
decimals: 6
},
// XDC Network mainnet USDC (Bridged USDC Standard, EIP-3009 supported)
"eip155:51": {
address: "0xb5AB69F7bBada22B28e79C8FFAECe55eF1c771D4",
name: "USDC",
version: "2",
decimals: 6
},
// XDC Apothem testnet USDC (Bridged USDC Standard, EIP-3009 supported)
"eip155:38833": {
address: "0xA5b8BF902b2844dA17d4506cc827F7F1681735E7",
name: "USDC",
version: "1",
decimals: 6,
assetTransferMethod: "permit2"
},
// Igra mainnet USDC (no EIP-3009, no EIP-2612)
"eip155:14": {
address: "0xe7cd86e13AC4309349F30B3435a9d337750fC82D",
name: "USD\u20AE0",
version: "1",
decimals: 6
},
// Flare mainnet USD₮0 (EIP-3009 supported)
"eip155:42220": {
address: "0xcebA9300f2b948710d2653dD7B07f33A8B32118C",
name: "USDC",
version: "2",
decimals: 6
},
// Celo mainnet USDC (EIP-3009 supported)
"eip155:11142220": {
address: "0x01C5C0122039549AD1493B8220cABEdD739BC44E",
name: "USDC",
version: "2",
decimals: 6
}
// Celo Sepolia testnet USDC (EIP-3009 supported)
};
function getDefaultAsset(network) {
const info = DEFAULT_STABLECOINS[network];
if (!info) {
throw new Error(`No default asset configured for network ${network}`);
}
return info;
}
export {
DEFAULT_STABLECOINS,
getDefaultAsset
};
//# sourceMappingURL=chunk-HR3TFOGA.mjs.map
{"version":3,"sources":["../../src/shared/defaultAssets.ts"],"sourcesContent":["import type { Network } from \"@x402/core/types\";\n\n/**\n * Base stablecoin asset configuration shared across all EVM payment schemes.\n * Contains the core fields needed to identify and convert tokens.\n */\nexport type DefaultAssetInfo = {\n /** Token contract address */\n address: string;\n /** EIP-712 domain name (must match the token's domain separator) */\n name: string;\n /** EIP-712 domain version (must match the token's domain separator) */\n version: string;\n /** Token decimal places (typically 6 for USDC) */\n decimals: number;\n};\n\n/**\n * Extended asset configuration for the exact scheme.\n * Includes transfer method hints that control client-side behaviour.\n */\nexport type ExactDefaultAssetInfo = DefaultAssetInfo & {\n /**\n * Transfer method override: `\"permit2\"` for tokens that don't support EIP-3009.\n * Omit for EIP-3009 tokens (default behaviour).\n */\n assetTransferMethod?: string;\n /**\n * Set to `true` for permit2 tokens that implement EIP-2612 `permit()`.\n * Controls whether name/version are included in `extra` so the client can\n * sign a gasless EIP-2612 permit for Permit2 approval.\n */\n supportsEip2612?: boolean;\n};\n\n/**\n * Default stablecoins indexed by CAIP-2 network identifier.\n *\n * Each network has the right to determine its own default stablecoin that can\n * be expressed as a USD string by calling servers. See DEFAULT_ASSETS.md at the\n * repository root for how to add new chains.\n */\nexport const DEFAULT_STABLECOINS: Record<string, ExactDefaultAssetInfo> = {\n \"eip155:8453\": {\n address: \"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913\",\n name: \"USD Coin\",\n version: \"2\",\n decimals: 6,\n }, // Base mainnet USDC\n \"eip155:84532\": {\n address: \"0x036CbD53842c5426634e7929541eC2318f3dCF7e\",\n name: \"USDC\",\n version: \"2\",\n decimals: 6,\n }, // Base Sepolia USDC\n \"eip155:4326\": {\n address: \"0xFAfDdbb3FC7688494971a79cc65DCa3EF82079E7\",\n name: \"MegaUSD\",\n version: \"1\",\n decimals: 18,\n assetTransferMethod: \"permit2\",\n supportsEip2612: true,\n }, // MegaETH mainnet MegaUSD (no EIP-3009, supports EIP-2612)\n \"eip155:143\": {\n address: \"0x754704Bc059F8C67012fEd69BC8A327a5aafb603\",\n name: \"USDC\",\n version: \"2\",\n decimals: 6,\n }, // Monad mainnet USDC\n \"eip155:988\": {\n address: \"0x779Ded0c9e1022225f8E0630b35a9b54bE713736\",\n name: \"USDT0\",\n version: \"1\",\n decimals: 6,\n }, // Stable mainnet USDT0\n \"eip155:2201\": {\n address: \"0x78Cf24370174180738C5B8E352B6D14c83a6c9A9\",\n name: \"USDT0\",\n version: \"1\",\n decimals: 6,\n }, // Stable testnet USDT0\n \"eip155:137\": {\n address: \"0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359\",\n name: \"USD Coin\",\n version: \"2\",\n decimals: 6,\n }, // Polygon mainnet USDC\n \"eip155:42161\": {\n address: \"0xaf88d065e77c8cC2239327C5EDb3A432268e5831\",\n name: \"USD Coin\",\n version: \"2\",\n decimals: 6,\n }, // Arbitrum One USDC\n \"eip155:421614\": {\n address: \"0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d\",\n name: \"USD Coin\",\n version: \"2\",\n decimals: 6,\n }, // Arbitrum Sepolia USDC\n \"eip155:31612\": {\n address: \"0xdD468A1DDc392dcdbEf6db6e34E89AA338F9F186\",\n name: \"Mezo USD\",\n version: \"1\",\n decimals: 18,\n assetTransferMethod: \"permit2\",\n supportsEip2612: true,\n }, // Mezo mainnet mUSD (no EIP-3009, supports EIP-2612)\n \"eip155:31611\": {\n address: \"0x118917a40FAF1CD7a13dB0Ef56C86De7973Ac503\",\n name: \"Mezo USD\",\n version: \"1\",\n decimals: 18,\n assetTransferMethod: \"permit2\",\n supportsEip2612: true,\n }, // Mezo Testnet mUSD (no EIP-3009, supports EIP-2612)\n \"eip155:723487\": {\n address: \"0x33ad9e4BD16B69B5BFdED37D8B5D9fF9aba014Fb\",\n name: \"Stable Coin\",\n version: \"1\",\n decimals: 6,\n assetTransferMethod: \"permit2\",\n supportsEip2612: true,\n }, // Radius Network SBC (no EIP-3009, supports EIP-2612)\n \"eip155:72344\": {\n address: \"0x33ad9e4BD16B69B5BFdED37D8B5D9fF9aba014Fb\",\n name: \"Stable Coin\",\n version: \"1\",\n decimals: 6,\n assetTransferMethod: \"permit2\",\n supportsEip2612: true,\n }, // Radius Testnet SBC (no EIP-3009, supports EIP-2612)\n \"eip155:36900\": {\n address: \"0x9cb8142aEBBcdc60AF7c97Af897A67A8f3CA71C2\",\n name: \"USDC.e\",\n version: \"2\",\n decimals: 6,\n }, // ADI Chain USDC.e (EIP-3009 supported)\n \"eip155:190415\": {\n address: \"0x401eCb1D350407f13ba348573E5630B83638E30D\",\n name: \"Bridged USDC\",\n version: \"2\",\n decimals: 6,\n }, // HPP mainnet USDC.e\n \"eip155:181228\": {\n address: \"0x401eCb1D350407f13ba348573E5630B83638E30D\",\n name: \"Bridged USDC\",\n version: \"2\",\n decimals: 6,\n }, // HPP Sepolia USDC.e\n \"eip155:50\": {\n address: \"0xfA2958CB79b0491CC627c1557F441eF849Ca8eb1\",\n name: \"USDC\",\n version: \"2\",\n decimals: 6,\n }, // XDC Network mainnet USDC (Bridged USDC Standard, EIP-3009 supported)\n \"eip155:51\": {\n address: \"0xb5AB69F7bBada22B28e79C8FFAECe55eF1c771D4\",\n name: \"USDC\",\n version: \"2\",\n decimals: 6,\n }, // XDC Apothem testnet USDC (Bridged USDC Standard, EIP-3009 supported)\n \"eip155:38833\": {\n address: \"0xA5b8BF902b2844dA17d4506cc827F7F1681735E7\",\n name: \"USDC\",\n version: \"1\",\n decimals: 6,\n assetTransferMethod: \"permit2\",\n }, // Igra mainnet USDC (no EIP-3009, no EIP-2612)\n \"eip155:14\": {\n address: \"0xe7cd86e13AC4309349F30B3435a9d337750fC82D\",\n name: \"USD\\u20AE0\",\n version: \"1\",\n decimals: 6,\n }, // Flare mainnet USD₮0 (EIP-3009 supported)\n \"eip155:42220\": {\n address: \"0xcebA9300f2b948710d2653dD7B07f33A8B32118C\",\n name: \"USDC\",\n version: \"2\",\n decimals: 6,\n }, // Celo mainnet USDC (EIP-3009 supported)\n \"eip155:11142220\": {\n address: \"0x01C5C0122039549AD1493B8220cABEdD739BC44E\",\n name: \"USDC\",\n version: \"2\",\n decimals: 6,\n }, // Celo Sepolia testnet USDC (EIP-3009 supported)\n};\n\n/**\n * Look up the default stablecoin for a network.\n *\n * @param network - CAIP-2 network identifier (e.g. \"eip155:8453\")\n * @returns The default asset info\n * @throws If no default asset is configured for the network\n */\nexport function getDefaultAsset(network: Network): ExactDefaultAssetInfo {\n const info = DEFAULT_STABLECOINS[network];\n if (!info) {\n throw new Error(`No default asset configured for network ${network}`);\n }\n return info;\n}\n"],"mappings":";AA0CO,IAAM,sBAA6D;AAAA,EACxE,eAAe;AAAA,IACb,SAAS;AAAA,IACT,MAAM;AAAA,IACN,SAAS;AAAA,IACT,UAAU;AAAA,EACZ;AAAA;AAAA,EACA,gBAAgB;AAAA,IACd,SAAS;AAAA,IACT,MAAM;AAAA,IACN,SAAS;AAAA,IACT,UAAU;AAAA,EACZ;AAAA;AAAA,EACA,eAAe;AAAA,IACb,SAAS;AAAA,IACT,MAAM;AAAA,IACN,SAAS;AAAA,IACT,UAAU;AAAA,IACV,qBAAqB;AAAA,IACrB,iBAAiB;AAAA,EACnB;AAAA;AAAA,EACA,cAAc;AAAA,IACZ,SAAS;AAAA,IACT,MAAM;AAAA,IACN,SAAS;AAAA,IACT,UAAU;AAAA,EACZ;AAAA;A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AS;AAAA,IACT,MAAM;AAAA,IACN,SAAS;AAAA,IACT,UAAU;AAAA,EACZ;AAAA;AAAA,EACA,iBAAiB;AAAA,IACf,SAAS;AAAA,IACT,MAAM;AAAA,IACN,SAAS;AAAA,IACT,UAAU;AAAA,EACZ;AAAA;AAAA,EACA,aAAa;AAAA,IACX,SAAS;AAAA,IACT,MAAM;AAAA,IACN,SAAS;AAAA,IACT,UAAU;AAAA,EACZ;AAAA;AAAA,EACA,aAAa;AAAA,IACX,SAAS;AAAA,IACT,MAAM;AAAA,IACN,SAAS;AAAA,IACT,UAAU;AAAA,EACZ;AAAA;AAAA,EACA,gBAAgB;AAAA,IACd,SAAS;AAAA,IACT,MAAM;AAAA,IACN,SAAS;AAAA,IACT,UAAU;AAAA,IACV,qBAAqB;AAAA,EACvB;AAAA;AAAA,EACA,aAAa;AAAA,IACX,SAAS;AAAA,IACT,MAAM;AAAA,IACN,SAAS;AAAA,IACT,UAAU;AAAA,EACZ;AAAA;AAAA,EACA,gBAAgB;AAAA,IACd,SAAS;AAAA,IACT,MAAM;AAAA,IACN,SAAS;AAAA,IACT,UAAU;AAAA,EACZ;AAAA;AAAA,EACA,mBAAmB;AAAA,IACjB,SAAS;AAAA,IACT,MAAM;AAAA,IACN,SAAS;AAAA,IACT,UAAU;AAAA,EACZ;AAAA;AACF;AASO,SAAS,gBAAgB,SAAyC;AACvE,QAAM,OAAO,oBAAoB,OAAO;AACxC,MAAI,CAAC,MAAM;AACT,UAAM,IAAI,MAAM,2CAA2C,OAAO,EAAE;AAAA,EACtE;AACA,SAAO;AACT;","names":[]}
import { PaymentRequirements, SettleResponse, SchemeNetworkClient, SchemeClientHooks, PaymentPayloadContext, PaymentPayloadResult, PaymentRequired } from '@x402/core/types';
import { C as ClientEvmSigner } from './signer-B127taDR.mjs';
import { C as ChannelConfig } from './types-B4ib_1f_.mjs';
import { c as EvmSchemeOptions } from './rpc-DULZzRne.mjs';
import { B as BatchSettlementClientContext, C as ClientChannelStorage } from './storage-BFpn16ZW.mjs';
/**
* Caller-tunable policy controlling how the client sizes channel deposits.
*/
interface BatchSettlementDepositPolicy {
depositMultiplier?: number;
}
/**
* Return shape for custom deposit sizing.
*/
type BatchSettlementDepositStrategyResult = string | bigint | false | undefined;
/**
* Information supplied before the client signs a deposit authorization.
*/
interface BatchSettlementDepositStrategyContext {
paymentRequirements: PaymentRequirements;
channelConfig: ChannelConfig;
channelId: `0x${string}`;
clientContext: BatchSettlementClientContext;
requestAmount: string;
maxClaimableAmount: string;
currentBalance: string;
minimumDepositAmount: string;
depositAmount: string;
}
/**
* Custom deposit sizing callback for initial deposits and top-ups.
*/
type BatchSettlementDepositStrategy = (context: BatchSettlementDepositStrategyContext) => BatchSettlementDepositStrategyResult | Promise<BatchSettlementDepositStrategyResult>;
/**
* Full options object accepted by `BatchSettlementEvmScheme`. Either this or a
* bare {@link BatchSettlementDepositPolicy} can be passed as the second
* constructor argument.
*/
interface BatchSettlementEvmSchemeOptions {
depositPolicy?: BatchSettlementDepositPolicy;
/** Optional callback for app-specific deposit sizing or skipping. */
depositStrategy?: BatchSettlementDepositStrategy;
storage?: ClientChannelStorage;
salt?: `0x${string}`;
payerAuthorizer?: `0x${string}`;
rpcUrl?: string;
/** When set, EIP-712 vouchers are signed with this key; deposits still use the main `signer`. */
voucherSigner?: ClientEvmSigner;
}
/**
* Resolved options after merging defaults — used internally by the scheme,
* recovery, and refund modules.
*/
interface ResolvedClientOptions {
depositPolicy?: BatchSettlementDepositPolicy;
depositStrategy?: BatchSettlementDepositStrategy;
storage: ClientChannelStorage;
salt: `0x${string}`;
payerAuthorizer?: `0x${string}`;
voucherSigner?: ClientEvmSigner;
extensionRpcOptions?: EvmSchemeOptions;
}
/**
* Discriminates a full options object from a bare deposit-policy object.
*
* @param o - Constructor argument that may be options, deposit policy only, or undefined.
* @returns `true` when `o` is a {@link BatchSettlementEvmSchemeOptions} object.
*/
declare function isBatchSettlementEvmSchemeOptions(o: BatchSettlementEvmSchemeOptions | BatchSettlementDepositPolicy | undefined): o is BatchSettlementEvmSchemeOptions;
/**
* Normalises the constructor's second argument into a uniform options shape.
*
* @param second - Optional second constructor argument (options or deposit policy).
* @returns Resolved storage, salt, deposit policy, and optional payer authorizer.
*/
declare function resolveClientOptions(second?: BatchSettlementEvmSchemeOptions | BatchSettlementDepositPolicy): ResolvedClientOptions;
/**
* Validates a {@link BatchSettlementDepositPolicy}, throwing on invalid fields.
*
* @param policy - The policy to validate (no-op when undefined).
*/
declare function validateDepositPolicy(policy: BatchSettlementDepositPolicy | undefined): void;
/**
* Computes the deposit amount based on the deposit multiplier.
*
* @param policy - Deposit policy controlling multiplier (may be undefined).
* @param requestAmount - Amount requested for this operation, in token base units.
* @returns Deposit amount string in token base units.
*/
declare function depositAmountForRequest(policy: BatchSettlementDepositPolicy | undefined, requestAmount: bigint): string;
/**
* Runtime dependency bag shared by every storage-bound client helper (channel,
* recovery, refund) and the {@link BatchSettlementEvmScheme} class.
*/
interface BatchSettlementClientDeps {
signer: ClientEvmSigner;
storage: ClientChannelStorage;
salt: `0x${string}`;
payerAuthorizer?: `0x${string}`;
voucherSigner?: ClientEvmSigner;
}
/**
* Constructs the immutable {@link ChannelConfig} from payment requirements and
* a client deps bag (signer, salt, optional payerAuthorizer / voucherSigner).
*
* @param deps - Client identity inputs.
* @param paymentRequirements - Server payment requirements providing receiver, asset, and extra fields.
* @returns The ChannelConfig that uniquely identifies this payment channel.
*/
declare function buildChannelConfig(deps: BatchSettlementClientDeps, paymentRequirements: PaymentRequirements): ChannelConfig;
/**
* Updates local channel state from a parsed `SettleResponse`.
*
* @param storage - Client channel storage.
* @param settle - The parsed settle response.
*/
declare function processSettleResponse(storage: ClientChannelStorage, settle: SettleResponse): Promise<void>;
/**
* Reconciles local channel state with the outcome of a cooperative refund.
*
* Deletes the channel record when the post-refund balance is zero (full refund),
* otherwise updates local state from the server snapshot.
*
* @param storage - Client channel storage.
* @param channelKey - Lowercased channel id used as the storage key.
* @param settleExtra - The `extra` block from the refund settle response.
*/
declare function updateChannelAfterRefund(storage: ClientChannelStorage, channelKey: string, settleExtra: Record<string, unknown>): Promise<void>;
/**
* Processes the `PAYMENT-RESPONSE` header after a successful request.
*
* Decodes the header into a `SettleResponse` and delegates to
* {@link processSettleResponse}.
*
* @param storage - Client channel storage.
* @param getHeader - Function to retrieve a response header by name.
*/
declare function processPaymentResponse(storage: ClientChannelStorage, getHeader: (name: string) => string | null | undefined): Promise<void>;
/**
* Recovers a channel record from onchain state (useful after a cold start or
* channel record loss).
*
* @param deps - Signer + storage + identity inputs.
* @param paymentRequirements - Server payment requirements used to derive the ChannelConfig.
* @returns The recovered client context.
*/
declare function recoverChannel(deps: BatchSettlementClientDeps, paymentRequirements: PaymentRequirements): Promise<BatchSettlementClientContext>;
/**
* Reads `channels(channelId)` returning `[balance, totalClaimed]`.
*
* @param signer - Signer providing `readContract`.
* @param channelId - The `bytes32` channel id to query.
* @returns Tuple of `[balance, totalClaimed]` as bigints.
*/
declare function readChannelBalanceAndTotalClaimed(signer: ClientEvmSigner, channelId: `0x${string}`): Promise<[bigint, bigint]>;
/**
* Returns whether a local channel record exists for the given channel.
*
* @param storage - Client channel storage.
* @param channelId - The channel identifier to check.
* @returns `true` when a channel record is stored.
*/
declare function hasChannel(storage: ClientChannelStorage, channelId: string): Promise<boolean>;
/**
* Returns the local channel context for a channel, if present.
*
* @param storage - Client channel storage.
* @param channelId - The channel identifier.
* @returns Stored context or `undefined`.
*/
declare function getChannel(storage: ClientChannelStorage, channelId: string): Promise<BatchSettlementClientContext | undefined>;
/**
* Caller-facing options for {@link refundChannel}.
*/
interface RefundOptions {
/** Token base units to refund; omit for a full refund (drains remaining balance). */
amount?: string;
/** Custom fetch implementation (defaults to `globalThis.fetch`). */
fetch?: typeof fetch;
}
/**
* Sends a cooperative refund request to the channel that backs `url`.
*
* Flow:
* 1. Probe the URL with `GET` (no payment) to obtain the route's payment requirements.
* 2. Build the `ChannelConfig` and resolve the local session (or recover it).
* 3. Sign a zero-charge refund voucher (`maxClaimableAmount = chargedCumulativeAmount`).
* 4. Send the voucher via `PAYMENT-SIGNATURE`. On a corrective 402, run the
* standard recovery path and retry once.
* 5. Return the parsed `SettleResponse` from the server.
*
* @param ctx - Identity inputs (storage, signers, salt, payerAuthorizer).
* @param url - Any protected route on the channel to refund (the resource handler is bypassed).
* @param options - Optional `amount` (partial refund) and `fetch` override.
* @returns The settle response describing the refund outcome.
* @throws When the probe fails, the receiver lacks an authorizer, or recovery fails.
*/
declare function refundChannel(ctx: BatchSettlementClientDeps, url: string, options?: RefundOptions): Promise<SettleResponse>;
/**
* Client-side implementation of the `batch-settlement` scheme for EVM networks.
*
* Builds payment payloads (deposit + voucher or voucher-only), processes server
* responses to update local session state via {@link processSettleResponse},
* handles corrective 402 resynchronisation via
* {@link processCorrectivePaymentRequired}, and supports on-demand cooperative
* refund requests via {@link refundChannel}.
*/
declare class BatchSettlementEvmScheme implements SchemeNetworkClient {
private readonly signer;
readonly scheme: "batch-settlement";
readonly schemeHooks: SchemeClientHooks;
private readonly storage;
private readonly depositPolicy;
private readonly depositStrategy;
private readonly salt;
private readonly payerAuthorizer;
private readonly voucherSigner;
private readonly extensionRpcOptions;
/**
* Constructs a batched client scheme.
*
* @param signer - Client EVM wallet used for signing vouchers and ERC-3009 authorizations.
* @param optionsOrPolicy - Either a full options object or a bare deposit-policy.
*/
constructor(signer: ClientEvmSigner, optionsOrPolicy?: BatchSettlementEvmSchemeOptions | BatchSettlementDepositPolicy);
/**
* Creates the payment payload for a batched request.
*
* If the channel has no onchain deposit (or needs a top-up), builds an
* ERC-3009 deposit payload bundled with a voucher. Otherwise, signs and
* returns a voucher-only payload.
*
* @param x402Version - Protocol version for the payload envelope.
* @param paymentRequirements - Server payment requirements (scheme, network, asset, amount).
* @param context - Optional payment payload context with extension hints.
* @returns A {@link PaymentPayloadResult} ready to be sent as the `X-PAYMENT` header.
*/
createPaymentPayload(x402Version: number, paymentRequirements: PaymentRequirements, context?: PaymentPayloadContext): Promise<PaymentPayloadResult>;
/**
* Sends a cooperative refund request.
*
* @param url - The route URL backing the channel to refund.
* @param options - Optional `amount` (partial refund) and `fetch` override.
* @returns The settle response describing the refund outcome.
*/
refund(url: string, options?: RefundOptions): Promise<SettleResponse>;
/**
* Updates local channel state from a settle response.
*
* @param settle - The parsed settle response from the server.
* @returns Resolves when local channel state has been updated.
*/
processSettleResponse(settle: SettleResponse): Promise<void>;
/**
* Resyncs local channel state from a corrective 402 response.
*
* @param paymentRequired - The decoded 402 response body.
* @returns `true` if local state was successfully resynced and a retry is warranted.
*/
processCorrectivePaymentRequired(paymentRequired: PaymentRequired): Promise<boolean>;
/**
* Builds the immutable {@link ChannelConfig} for a given set of payment
* requirements, using the scheme's own signer and salt.
*
* @param paymentRequirements - Server payment requirements for the channel.
* @returns The channel config that uniquely identifies the payment channel.
*/
buildChannelConfig(paymentRequirements: PaymentRequirements): ChannelConfig;
/**
* Resolves the deposit amount after applying the optional custom strategy.
*
* @param context - Deposit attempt context exposed to the strategy.
* @returns The deposit amount to sign, or `false` to skip this deposit attempt.
*/
private resolveDepositAmount;
/**
* Normalizes and validates a strategy-provided base-unit deposit amount.
*
* @param value - Strategy-provided string or bigint amount.
* @returns Normalized decimal string.
*/
private normalizeStrategyDepositAmount;
/**
* Signs a voucher-only payment payload for the current channel.
*
* @param x402Version - Protocol version for the payload envelope.
* @param channelId - Channel identifier for the voucher.
* @param maxClaimableAmount - Cumulative ceiling for the voucher.
* @param network - CAIP-2 network identifier.
* @param config - Immutable channel configuration.
* @returns Voucher-only payment payload.
*/
private createVoucherPayload;
/**
* Bundles the class state into the {@link BatchSettlementClientDeps} shape
* consumed by the `channel`, `recovery`, and `refund` modules.
*
* @returns Client deps wrapping the scheme's own signer and storage.
*/
private deps;
}
export { type BatchSettlementClientDeps as B, type RefundOptions as R, BatchSettlementEvmScheme as a, type BatchSettlementDepositPolicy as b, type BatchSettlementDepositStrategy as c, type BatchSettlementDepositStrategyContext as d, type BatchSettlementDepositStrategyResult as e, type BatchSettlementEvmSchemeOptions as f, depositAmountForRequest as g, resolveClientOptions as h, isBatchSettlementEvmSchemeOptions as i, type ResolvedClientOptions as j, buildChannelConfig as k, getChannel as l, hasChannel as m, processSettleResponse as n, readChannelBalanceAndTotalClaimed as o, processPaymentResponse as p, recoverChannel as q, refundChannel as r, updateChannelAfterRefund as u, validateDepositPolicy as v };
import { C as ChannelConfig } from './types-B4ib_1f_.mjs';
interface Channel {
channelId: string;
channelConfig: ChannelConfig;
chargedCumulativeAmount: string;
signedMaxClaimable: string;
signature: string;
balance: string;
totalClaimed: string;
withdrawRequestedAt: number;
refundNonce: number;
onchainSyncedAt?: number;
lastRequestTimestamp: number;
pendingRequest?: PendingRequest;
}
interface PendingRequest {
pendingId: string;
signedMaxClaimable: string;
expiresAt: number;
}
interface ChannelUpdateResult {
channel: Channel | undefined;
status: "updated" | "unchanged" | "deleted";
}
interface ChannelStorage {
get(channelId: string): Promise<Channel | undefined>;
list(): Promise<Channel[]>;
/**
* Atomically inspects and mutates a channel record.
*
* Implementations must guarantee that no concurrent mutation can interleave between
* reading `current` and writing the callback result for all application instances that
* share the backend. The in-memory backend only provides this guarantee inside one JS
* runtime; production multi-instance deployments need storage with backend-level atomic
* conditional mutation, such as Redis/Valkey Lua scripts, SQL transactions, or Durable Objects.
*
* @param channelId - The channel identifier.
* @param update - Mutation callback. Return `undefined` to delete, or `current` to leave unchanged.
* @returns The final stored channel and whether storage updated, stayed unchanged, or deleted.
*/
updateChannel(channelId: string, update: (current: Channel | undefined) => Channel | undefined): Promise<ChannelUpdateResult>;
}
/**
* In-memory {@link ChannelStorage} backed by a Map keyed by `channelId`.
*/
declare class InMemoryChannelStorage implements ChannelStorage {
private readonly channels;
private readonly channelLocks;
/**
* Returns the channel record for a channel, if present.
*
* @param channelId - The channel identifier.
* @returns The channel record or undefined when not found.
*/
get(channelId: string): Promise<Channel | undefined>;
/**
* Lists all stored channel records.
*
* @returns All channel records in storage.
*/
list(): Promise<Channel[]>;
/**
* Atomically inspects and mutates a channel record while holding a per-channel lock.
*
* @param channelId - The channel identifier.
* @param update - Mutation callback. Return `undefined` to delete, or `current` to leave unchanged.
* @returns The final stored channel and whether storage updated, stayed unchanged, or deleted.
*/
updateChannel(channelId: string, update: (current: Channel | undefined) => Channel | undefined): Promise<ChannelUpdateResult>;
/**
* Runs `fn` after any prior locked work for the same channel key has finished.
*
* @param key - Lowercased channel id used as the lock key.
* @param fn - Async work to run while holding the logical per-channel lock.
* @returns The resolved result of `fn`.
*/
private withChannelLock;
}
export { type ChannelStorage as C, InMemoryChannelStorage as I, type PendingRequest as P, type Channel as a, type ChannelUpdateResult as b };
import { TypedData } from 'viem';
interface AuthorizerSigner {
address: `0x${string}`;
signTypedData(params: {
domain: Record<string, unknown>;
types: TypedData;
primaryType: string;
message: Record<string, unknown>;
}): Promise<`0x${string}`>;
}
type ChannelState = {
balance: bigint;
totalClaimed: bigint;
withdrawRequestedAt: number;
refundNonce: bigint;
};
type ChannelConfig = {
payer: `0x${string}`;
payerAuthorizer: `0x${string}`;
receiver: `0x${string}`;
receiverAuthorizer: `0x${string}`;
token: `0x${string}`;
withdrawDelay: number;
salt: `0x${string}`;
};
type BatchSettlementErc3009Authorization = {
validAfter: string;
validBefore: string;
salt: `0x${string}`;
signature: `0x${string}`;
};
type BatchSettlementPermit2Authorization = {
from: `0x${string}`;
permitted: {
token: `0x${string}`;
amount: string;
};
spender: `0x${string}`;
nonce: string;
deadline: string;
witness: {
channelId: `0x${string}`;
};
signature: `0x${string}`;
};
type BatchSettlementAssetTransferMethod = "eip3009" | "permit2";
type BatchSettlementDepositAuthorization = {
erc3009Authorization: BatchSettlementErc3009Authorization;
permit2Authorization?: never;
} | {
erc3009Authorization?: never;
permit2Authorization: BatchSettlementPermit2Authorization;
};
type BatchSettlementDepositPayload = {
type: "deposit";
channelConfig: ChannelConfig;
voucher: BatchSettlementVoucherFields;
deposit: {
amount: string;
authorization: BatchSettlementDepositAuthorization;
};
};
type BatchSettlementVoucherPayload = {
type: "voucher";
channelConfig: ChannelConfig;
voucher: BatchSettlementVoucherFields;
};
type BatchSettlementRefundPayload = {
type: "refund";
channelConfig: ChannelConfig;
voucher: BatchSettlementVoucherFields;
amount?: string;
};
type BatchSettlementVoucherFields = {
channelId: `0x${string}`;
maxClaimableAmount: string;
signature: `0x${string}`;
};
type BatchSettlementVoucherClaim = {
voucher: {
channel: ChannelConfig;
maxClaimableAmount: string;
};
signature: `0x${string}`;
totalClaimed: string;
};
type BatchSettlementChannelStateExtra = {
channelId: `0x${string}`;
balance: string;
totalClaimed: string;
withdrawRequestedAt: number;
refundNonce: string;
chargedCumulativeAmount?: string;
};
type BatchSettlementVoucherStateExtra = {
signedMaxClaimable?: string;
signature?: `0x${string}`;
};
type BatchSettlementPaymentRequirementsExtra = {
receiverAuthorizer: `0x${string}`;
withdrawDelay: number;
name: string;
version: string;
assetTransferMethod?: BatchSettlementAssetTransferMethod;
channelState?: BatchSettlementChannelStateExtra;
voucherState?: BatchSettlementVoucherStateExtra;
};
type FileChannelStorageOptions = {
/** Root directory; channels are stored under `{directory}/{client|server}/{channelId}.json`. */
directory: string;
};
type BatchSettlementPaymentResponseExtra = {
chargedAmount?: string;
channelState?: BatchSettlementChannelStateExtra;
voucherState?: BatchSettlementVoucherStateExtra;
};
type BatchSettlementClaimPayload = {
type: "claim";
claims: BatchSettlementVoucherClaim[];
claimAuthorizerSignature?: `0x${string}`;
};
type BatchSettlementSettlePayload = {
type: "settle";
receiver: `0x${string}`;
token: `0x${string}`;
};
type BatchSettlementEnrichedRefundPayload = BatchSettlementRefundPayload & {
amount: string;
refundNonce: string;
claims: BatchSettlementVoucherClaim[];
refundAuthorizerSignature?: `0x${string}`;
claimAuthorizerSignature?: `0x${string}`;
};
type BatchSettlementPayload = BatchSettlementDepositPayload | BatchSettlementVoucherPayload | BatchSettlementRefundPayload;
type BatchSettlementFacilitatorSettlePayload = BatchSettlementDepositPayload | BatchSettlementClaimPayload | BatchSettlementSettlePayload | BatchSettlementEnrichedRefundPayload;
/**
* Type guard for {@link BatchSettlementDepositPayload}.
*
* @param payload - Unknown payload to check.
* @returns True if `payload` is a deposit payload (carries `deposit` and `voucher`).
*/
declare function isBatchSettlementDepositPayload(payload: unknown): payload is BatchSettlementDepositPayload;
/**
* Type guard for {@link BatchSettlementVoucherPayload}.
*
* @param payload - Unknown payload to check.
* @returns True if `payload` is a voucher payload with channel and signature fields.
*/
declare function isBatchSettlementVoucherPayload(payload: unknown): payload is BatchSettlementVoucherPayload;
/**
* Type guard for {@link BatchSettlementRefundPayload}.
*
* @param payload - Unknown payload to check.
* @returns True if `payload` is a refund payload with channel config and voucher fields.
*/
declare function isBatchSettlementRefundPayload(payload: unknown): payload is BatchSettlementRefundPayload;
/**
* Type guard for {@link BatchSettlementClaimPayload}.
*
* @param payload - Unknown payload to check.
* @returns True if `payload` is a settle-action `claimWithSignature` payload.
*/
declare function isBatchSettlementClaimPayload(payload: unknown): payload is BatchSettlementClaimPayload;
/**
* Type guard for {@link BatchSettlementSettlePayload}.
*
* @param payload - Unknown payload to check.
* @returns True if `payload` is a settle-action `settle` payload.
*/
declare function isBatchSettlementSettlePayload(payload: unknown): payload is BatchSettlementSettlePayload;
/**
* Type guard for {@link BatchSettlementEnrichedRefundPayload}.
*
* @param payload - Unknown payload to check.
* @returns True if `payload` is a settle-action `refundWithSignature` payload.
*/
declare function isBatchSettlementEnrichedRefundPayload(payload: unknown): payload is BatchSettlementEnrichedRefundPayload;
export { type AuthorizerSigner as A, type BatchSettlementVoucherClaim as B, type ChannelConfig as C, type FileChannelStorageOptions as F, type BatchSettlementAssetTransferMethod as a, type BatchSettlementVoucherFields as b, type BatchSettlementChannelStateExtra as c, type BatchSettlementVoucherStateExtra as d, type ChannelState as e, type BatchSettlementDepositPayload as f, type BatchSettlementVoucherPayload as g, type BatchSettlementRefundPayload as h, type BatchSettlementErc3009Authorization as i, type BatchSettlementClaimPayload as j, type BatchSettlementEnrichedRefundPayload as k, type BatchSettlementPayload as l, type BatchSettlementSettlePayload as m, type BatchSettlementFacilitatorSettlePayload as n, type BatchSettlementPaymentRequirementsExtra as o, type BatchSettlementPaymentResponseExtra as p, isBatchSettlementDepositPayload as q, isBatchSettlementVoucherPayload as r, isBatchSettlementRefundPayload as s, isBatchSettlementClaimPayload as t, isBatchSettlementSettlePayload as u, isBatchSettlementEnrichedRefundPayload as v };
/**
* Asset transfer methods for the exact EVM scheme.
* - eip3009: Uses transferWithAuthorization (USDC, etc.) - recommended for compatible tokens
* - permit2: Uses Permit2 + x402Permit2Proxy - universal fallback for any ERC-20
*/
type AssetTransferMethod = "eip3009" | "permit2";
/**
* EIP-3009 payload for tokens with native transferWithAuthorization support.
*/
type ExactEIP3009Payload = {
signature?: `0x${string}`;
authorization: {
from: `0x${string}`;
to: `0x${string}`;
value: string;
validAfter: string;
validBefore: string;
nonce: `0x${string}`;
};
};
/**
* Permit2 witness data structure.
* Matches the Witness struct in x402Permit2Proxy contract.
* Note: Upper time bound is enforced by Permit2's `deadline` field, not a witness field.
*/
type Permit2Witness = {
to: `0x${string}`;
validAfter: string;
};
/**
* Permit2 authorization parameters.
* Used to reconstruct the signed message for verification.
*/
type Permit2Authorization = {
permitted: {
token: `0x${string}`;
amount: string;
};
spender: `0x${string}`;
nonce: string;
deadline: string;
witness: Permit2Witness;
};
/**
* Permit2 payload for tokens using the Permit2 + x402Permit2Proxy flow.
*/
type ExactPermit2Payload = {
signature: `0x${string}`;
permit2Authorization: Permit2Authorization & {
from: `0x${string}`;
};
};
type ExactEvmPayloadV1 = ExactEIP3009Payload;
type ExactEvmPayloadV2 = ExactEIP3009Payload | ExactPermit2Payload;
/**
* Type guard to check if a payload is a Permit2 payload.
* Permit2 payloads have a `permit2Authorization` field.
*
* @param payload - The payload to check.
* @returns True if the payload is a Permit2 payload, false otherwise.
*/
declare function isPermit2Payload(payload: ExactEvmPayloadV2): payload is ExactPermit2Payload;
/**
* Type guard to check if a payload is an EIP-3009 payload.
* EIP-3009 payloads have an `authorization` field.
*
* @param payload - The payload to check.
* @returns True if the payload is an EIP-3009 payload, false otherwise.
*/
declare function isEIP3009Payload(payload: ExactEvmPayloadV2): payload is ExactEIP3009Payload;
/**
* Upto Permit2 witness — includes `facilitator` field absent from exact witness.
* Only the address matching `witness.facilitator` can call settle() on-chain.
*/
type UptoPermit2Witness = {
to: `0x${string}`;
facilitator: `0x${string}`;
validAfter: string;
};
type UptoPermit2Authorization = {
permitted: {
token: `0x${string}`;
amount: string;
};
spender: `0x${string}`;
nonce: string;
deadline: string;
witness: UptoPermit2Witness;
};
type UptoPermit2Payload = {
signature: `0x${string}`;
permit2Authorization: UptoPermit2Authorization & {
from: `0x${string}`;
};
};
/**
* Type guard to check if a payload is an upto Permit2 payload.
* Validates structural presence of all required fields: signature, permit2Authorization
* (with from, permitted, spender, nonce, deadline), and a witness containing facilitator.
*
* @param payload - The payload to check.
* @returns True if the payload is an upto Permit2 payload, false otherwise.
*/
declare function isUptoPermit2Payload(payload: Record<string, unknown>): payload is UptoPermit2Payload;
export { type AssetTransferMethod as A, type ExactEIP3009Payload as E, type Permit2Witness as P, type UptoPermit2Payload as U, type ExactPermit2Payload as a, type ExactEvmPayloadV1 as b, type ExactEvmPayloadV2 as c, type Permit2Authorization as d, isEIP3009Payload as e, type UptoPermit2Witness as f, type UptoPermit2Authorization as g, isUptoPermit2Payload as h, isPermit2Payload as i };
+1
-1

@@ -1,2 +0,2 @@

import { F as FileChannelStorageOptions } from '../../types-DIt9uAUy.js';
import { F as FileChannelStorageOptions } from '../../types-B4ib_1f_.js';
import { C as ClientChannelStorage, B as BatchSettlementClientContext } from '../../storage-BFpn16ZW.js';

@@ -3,0 +3,0 @@ import 'viem';

@@ -1,7 +0,7 @@

import { B as BatchSettlementClientDeps } from '../../scheme-B-ZpMjZp.js';
export { b as BatchSettlementDepositPolicy, c as BatchSettlementDepositStrategy, d as BatchSettlementDepositStrategyContext, e as BatchSettlementDepositStrategyResult, a as BatchSettlementEvmScheme, f as BatchSettlementEvmSchemeOptions, R as RefundOptions, j as ResolvedClientOptions, k as buildChannelConfig, g as depositAmountForRequest, l as getChannel, m as hasChannel, i as isBatchSettlementEvmSchemeOptions, p as processPaymentResponse, n as processSettleResponse, o as readChannelBalanceAndTotalClaimed, q as recoverChannel, r as refundChannel, h as resolveClientOptions, u as updateChannelAfterRefund, v as validateDepositPolicy } from '../../scheme-B-ZpMjZp.js';
import { B as BatchSettlementClientDeps } from '../../scheme-C41SfdnU.js';
export { b as BatchSettlementDepositPolicy, c as BatchSettlementDepositStrategy, d as BatchSettlementDepositStrategyContext, e as BatchSettlementDepositStrategyResult, a as BatchSettlementEvmScheme, f as BatchSettlementEvmSchemeOptions, R as RefundOptions, j as ResolvedClientOptions, k as buildChannelConfig, g as depositAmountForRequest, l as getChannel, m as hasChannel, i as isBatchSettlementEvmSchemeOptions, p as processPaymentResponse, n as processSettleResponse, o as readChannelBalanceAndTotalClaimed, q as recoverChannel, r as refundChannel, h as resolveClientOptions, u as updateChannelAfterRefund, v as validateDepositPolicy } from '../../scheme-C41SfdnU.js';
export { B as BatchSettlementClientContext, C as ClientChannelStorage, I as InMemoryClientChannelStorage } from '../../storage-BFpn16ZW.js';
import { PaymentRequirements, PaymentPayloadResult, SchemeClientHooks, PaymentRequired } from '@x402/core/types';
import { C as ClientEvmSigner } from '../../signer-B127taDR.js';
import { C as ChannelConfig, a as BatchSettlementVoucherFields, b as BatchSettlementChannelStateExtra, c as BatchSettlementVoucherStateExtra } from '../../types-DIt9uAUy.js';
import { C as ChannelConfig, b as BatchSettlementVoucherFields, c as BatchSettlementChannelStateExtra, d as BatchSettlementVoucherStateExtra } from '../../types-B4ib_1f_.js';
import { PaymentResponseContext } from '@x402/core/client';

@@ -8,0 +8,0 @@ import '../../rpc-DULZzRne.js';

import { SchemeNetworkFacilitator, PaymentPayload, PaymentRequirements, FacilitatorContext, VerifyResponse, SettleResponse } from '@x402/core/types';
import { F as FacilitatorEvmSigner } from '../../signer-B127taDR.js';
import { A as AuthorizerSigner } from '../../types-DIt9uAUy.js';
import { A as AuthorizerSigner } from '../../types-B4ib_1f_.js';
import 'viem';

@@ -5,0 +5,0 @@

@@ -1,3 +0,3 @@

import { F as FileChannelStorageOptions } from '../../types-DIt9uAUy.js';
import { C as ChannelStorage, a as Channel, b as ChannelUpdateResult } from '../../storage-DjCv5IPh.js';
import { F as FileChannelStorageOptions } from '../../types-B4ib_1f_.js';
import { C as ChannelStorage, a as Channel, b as ChannelUpdateResult } from '../../storage-xgzm9G4m.js';
import 'viem';

@@ -4,0 +4,0 @@

import { Network, SchemePaymentRequiredContext, SchemeNetworkServer, SchemeServerHooks, PaymentRequirements, DeepReadonly, PaymentPayload, MoneyParser, Price, AssetAmount, SupportedKind } from '@x402/core/types';
import { FacilitatorClient, SettleContext, SettleResultContext } from '@x402/core/server';
import { B as BatchSettlementVoucherClaim, A as AuthorizerSigner } from '../../types-DIt9uAUy.js';
import { a as Channel, C as ChannelStorage } from '../../storage-DjCv5IPh.js';
export { b as ChannelUpdateResult, I as InMemoryChannelStorage, P as PendingRequest } from '../../storage-DjCv5IPh.js';
import { B as BatchSettlementVoucherClaim, a as BatchSettlementAssetTransferMethod, A as AuthorizerSigner } from '../../types-B4ib_1f_.js';
import { a as Channel, C as ChannelStorage } from '../../storage-xgzm9G4m.js';
export { b as ChannelUpdateResult, I as InMemoryChannelStorage, P as PendingRequest } from '../../storage-xgzm9G4m.js';
import 'viem';

@@ -325,2 +325,13 @@

readonly scheme: "batch-settlement";
readonly defaultAssetTransferMethod: BatchSettlementAssetTransferMethod;
readonly paymentFlows: {
readonly eip3009: {
readonly supported: readonly ["authorization"];
readonly default: "authorization";
};
readonly permit2: {
readonly supported: readonly ["authorization"];
readonly default: "authorization";
};
};
readonly schemeHooks: SchemeServerHooks;

@@ -327,0 +338,0 @@ private readonly requestContexts;

@@ -1,3 +0,3 @@

import { C as ChannelStorage, a as Channel, b as ChannelUpdateResult } from '../../storage-DjCv5IPh.js';
import '../../types-DIt9uAUy.js';
import { C as ChannelStorage, a as Channel, b as ChannelUpdateResult } from '../../storage-xgzm9G4m.js';
import '../../types-B4ib_1f_.js';
import 'viem';

@@ -4,0 +4,0 @@

import { SchemeNetworkServer, MoneyParser, Network, Price, AssetAmount, PaymentRequirements } from '@x402/core/types';
import { A as AssetTransferMethod } from '../../types-BBC1mC8d.js';
import { x402ResourceServer } from '@x402/core/server';

@@ -9,2 +10,13 @@

readonly scheme = "exact";
readonly defaultAssetTransferMethod: AssetTransferMethod;
readonly paymentFlows: {
readonly eip3009: {
readonly supported: readonly ["authorization"];
readonly default: "authorization";
};
readonly permit2: {
readonly supported: readonly ["authorization"];
readonly default: "authorization";
};
};
private moneyParsers;

@@ -11,0 +23,0 @@ /**

@@ -58,3 +58,3 @@ "use strict";

address: "0x754704Bc059F8C67012fEd69BC8A327a5aafb603",
name: "USD Coin",
name: "USDC",
version: "2",

@@ -212,2 +212,7 @@ decimals: 6

this.scheme = "exact";
this.defaultAssetTransferMethod = "eip3009";
this.paymentFlows = {
eip3009: { supported: ["authorization"], default: "authorization" },
permit2: { supported: ["authorization"], default: "authorization" }
};
this.moneyParsers = [];

@@ -214,0 +219,0 @@ }

@@ -1,1 +0,1 @@

{"version":3,"sources":["../../../../src/exact/server/index.ts","../../../../src/exact/server/scheme.ts","../../../../src/shared/defaultAssets.ts","../../../../src/exact/server/register.ts"],"sourcesContent":["export { ExactEvmScheme } from \"./scheme\";\nexport { registerExactEvmScheme } from \"./register\";\nexport type { EvmResourceServerConfig } from \"./register\";\n","import {\n AssetAmount,\n Network,\n PaymentRequirements,\n Price,\n SchemeNetworkServer,\n MoneyParser,\n} from \"@x402/core/types\";\nimport { convertToTokenAmount, numberToDecimalString, parseMoneyString } from \"@x402/core/utils\";\nimport { getDefaultAsset, type ExactDefaultAssetInfo } from \"../../shared/defaultAssets\";\n\n/**\n * EVM server implementation for the Exact payment scheme.\n */\nexport class ExactEvmScheme implements SchemeNetworkServer {\n readonly scheme = \"exact\";\n private moneyParsers: MoneyParser[] = [];\n\n /**\n * Register a custom money parser in the parser chain.\n * Multiple parsers can be registered - they will be tried in registration order.\n * Each parser receives a decimal amount (e.g., 1.50 for $1.50).\n * If a parser returns null, the next parser in the chain will be tried.\n * The default parser is always the final fallback.\n *\n * @param parser - Custom function to convert amount to AssetAmount (or null to skip)\n * @returns The server instance for chaining\n *\n * @example\n * evmServer.registerMoneyParser(async (amount, network) => {\n * // Custom conversion logic\n * if (amount > 100) {\n * // Use different token for large amounts\n * return { amount: (amount * 1e18).toString(), asset: \"0xCustomToken\" };\n * }\n * return null; // Use next parser\n * });\n */\n registerMoneyParser(parser: MoneyParser): ExactEvmScheme {\n this.moneyParsers.push(parser);\n return this;\n }\n\n /**\n * Returns the decimal precision of the default stablecoin for the given network.\n * Implements the optional AssetDecimalsProvider interface used by resolveSettlementOverrideAmount.\n *\n * @param _asset - The asset symbol (unused; defaults to the network's default stablecoin)\n * @param network - The network to look up the default asset for\n * @returns The number of decimal places for the asset\n */\n getAssetDecimals(_asset: string, network: Network): number {\n try {\n return getDefaultAsset(network).decimals;\n } catch {\n return 6;\n }\n }\n\n /**\n * Parses a price into an asset amount.\n * If price is already an AssetAmount, returns it directly.\n * If price is Money (string | number), parses to decimal and tries custom parsers.\n * Falls back to default conversion if all custom parsers return null.\n *\n * @param price - The price to parse\n * @param network - The network to use\n * @returns Promise that resolves to the parsed asset amount\n */\n async parsePrice(price: Price, network: Network): Promise<AssetAmount> {\n // If already an AssetAmount, return it directly\n if (typeof price === \"object\" && price !== null && \"amount\" in price) {\n if (!price.asset) {\n throw new Error(`Asset address must be specified for AssetAmount on network ${network}`);\n }\n return {\n amount: price.amount,\n asset: price.asset,\n extra: price.extra || {},\n };\n }\n\n // Parse Money to decimal number\n const amount = this.parseMoneyToDecimal(price);\n\n // Try each custom money parser in order\n for (const parser of this.moneyParsers) {\n const result = await parser(amount, network);\n if (result !== null) {\n return result;\n }\n }\n\n // All custom parsers returned null, use default conversion\n return this.defaultMoneyConversion(amount, network);\n }\n\n /**\n * Build payment requirements for this scheme/network combination\n *\n * @param paymentRequirements - The base payment requirements\n * @param supportedKind - The supported kind from facilitator (unused)\n * @param supportedKind.x402Version - The x402 version\n * @param supportedKind.scheme - The logical payment scheme\n * @param supportedKind.network - The network identifier in CAIP-2 format\n * @param supportedKind.extra - Optional extra metadata regarding scheme/network implementation details\n * @param extensionKeys - Extension keys supported by the facilitator (unused)\n * @returns Payment requirements ready to be sent to clients\n */\n enhancePaymentRequirements(\n paymentRequirements: PaymentRequirements,\n supportedKind: {\n x402Version: number;\n scheme: string;\n network: Network;\n extra?: Record<string, unknown>;\n },\n extensionKeys: string[],\n ): Promise<PaymentRequirements> {\n // Mark unused parameters to satisfy linter\n void supportedKind;\n void extensionKeys;\n return Promise.resolve(paymentRequirements);\n }\n\n /**\n * Parse Money (string | number) to a decimal number.\n * Handles formats like \"$1.50\", \"1.50\", 1.50, etc.\n *\n * @param money - The money value to parse\n * @returns Decimal number\n */\n private parseMoneyToDecimal(money: string | number): number {\n if (typeof money === \"number\") {\n return money;\n }\n\n return parseMoneyString(money);\n }\n\n /**\n * Converts a numeric dollar amount to an AssetAmount using the default token for the network.\n *\n * @param amount - The dollar amount as a number\n * @param network - The target network\n * @returns The converted asset amount with token metadata\n */\n private defaultMoneyConversion(amount: number, network: Network): AssetAmount {\n const assetInfo: ExactDefaultAssetInfo = getDefaultAsset(network);\n const tokenAmount = convertToTokenAmount(numberToDecimalString(amount), assetInfo.decimals);\n\n // EIP-3009 tokens always need name/version for their transferWithAuthorization domain.\n // Permit2 tokens only need them if the token supports EIP-2612 (for gasless permit signing).\n // Omitting name/version for permit2 tokens signals the client to skip EIP-2612 and use\n // ERC-20 approval gas sponsoring instead.\n const includeEip712Domain = !assetInfo.assetTransferMethod || assetInfo.supportsEip2612;\n\n return {\n amount: tokenAmount,\n asset: assetInfo.address,\n extra: {\n ...(includeEip712Domain && {\n name: assetInfo.name,\n version: assetInfo.version,\n }),\n ...(assetInfo.assetTransferMethod && {\n assetTransferMethod: assetInfo.assetTransferMethod,\n }),\n },\n };\n }\n}\n","import type { Network } from \"@x402/core/types\";\n\n/**\n * Base stablecoin asset configuration shared across all EVM payment schemes.\n * Contains the core fields needed to identify and convert tokens.\n */\nexport type DefaultAssetInfo = {\n /** Token contract address */\n address: string;\n /** EIP-712 domain name (must match the token's domain separator) */\n name: string;\n /** EIP-712 domain version (must match the token's domain separator) */\n version: string;\n /** Token decimal places (typically 6 for USDC) */\n decimals: number;\n};\n\n/**\n * Extended asset configuration for the exact scheme.\n * Includes transfer method hints that control client-side behaviour.\n */\nexport type ExactDefaultAssetInfo = DefaultAssetInfo & {\n /**\n * Transfer method override: `\"permit2\"` for tokens that don't support EIP-3009.\n * Omit for EIP-3009 tokens (default behaviour).\n */\n assetTransferMethod?: string;\n /**\n * Set to `true` for permit2 tokens that implement EIP-2612 `permit()`.\n * Controls whether name/version are included in `extra` so the client can\n * sign a gasless EIP-2612 permit for Permit2 approval.\n */\n supportsEip2612?: boolean;\n};\n\n/**\n * Default stablecoins indexed by CAIP-2 network identifier.\n *\n * Each network has the right to determine its own default stablecoin that can\n * be expressed as a USD string by calling servers. See DEFAULT_ASSETS.md at the\n * repository root for how to add new chains.\n */\nexport const DEFAULT_STABLECOINS: Record<string, ExactDefaultAssetInfo> = {\n \"eip155:8453\": {\n address: \"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913\",\n name: \"USD Coin\",\n version: \"2\",\n decimals: 6,\n }, // Base mainnet USDC\n \"eip155:84532\": {\n address: \"0x036CbD53842c5426634e7929541eC2318f3dCF7e\",\n name: \"USDC\",\n version: \"2\",\n decimals: 6,\n }, // Base Sepolia USDC\n \"eip155:4326\": {\n address: \"0xFAfDdbb3FC7688494971a79cc65DCa3EF82079E7\",\n name: \"MegaUSD\",\n version: \"1\",\n decimals: 18,\n assetTransferMethod: \"permit2\",\n supportsEip2612: true,\n }, // MegaETH mainnet MegaUSD (no EIP-3009, supports EIP-2612)\n \"eip155:143\": {\n address: \"0x754704Bc059F8C67012fEd69BC8A327a5aafb603\",\n name: \"USD Coin\",\n version: \"2\",\n decimals: 6,\n }, // Monad mainnet USDC\n \"eip155:988\": {\n address: \"0x779Ded0c9e1022225f8E0630b35a9b54bE713736\",\n name: \"USDT0\",\n version: \"1\",\n decimals: 6,\n }, // Stable mainnet USDT0\n \"eip155:2201\": {\n address: \"0x78Cf24370174180738C5B8E352B6D14c83a6c9A9\",\n name: \"USDT0\",\n version: \"1\",\n decimals: 6,\n }, // Stable testnet USDT0\n \"eip155:137\": {\n address: \"0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359\",\n name: \"USD Coin\",\n version: \"2\",\n decimals: 6,\n }, // Polygon mainnet USDC\n \"eip155:42161\": {\n address: \"0xaf88d065e77c8cC2239327C5EDb3A432268e5831\",\n name: \"USD Coin\",\n version: \"2\",\n decimals: 6,\n }, // Arbitrum One USDC\n \"eip155:421614\": {\n address: \"0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d\",\n name: \"USD Coin\",\n version: \"2\",\n decimals: 6,\n }, // Arbitrum Sepolia USDC\n \"eip155:31612\": {\n address: \"0xdD468A1DDc392dcdbEf6db6e34E89AA338F9F186\",\n name: \"Mezo USD\",\n version: \"1\",\n decimals: 18,\n assetTransferMethod: \"permit2\",\n supportsEip2612: true,\n }, // Mezo mainnet mUSD (no EIP-3009, supports EIP-2612)\n \"eip155:31611\": {\n address: \"0x118917a40FAF1CD7a13dB0Ef56C86De7973Ac503\",\n name: \"Mezo USD\",\n version: \"1\",\n decimals: 18,\n assetTransferMethod: \"permit2\",\n supportsEip2612: true,\n }, // Mezo Testnet mUSD (no EIP-3009, supports EIP-2612)\n \"eip155:723487\": {\n address: \"0x33ad9e4BD16B69B5BFdED37D8B5D9fF9aba014Fb\",\n name: \"Stable Coin\",\n version: \"1\",\n decimals: 6,\n assetTransferMethod: \"permit2\",\n supportsEip2612: true,\n }, // Radius Network SBC (no EIP-3009, supports EIP-2612)\n \"eip155:72344\": {\n address: \"0x33ad9e4BD16B69B5BFdED37D8B5D9fF9aba014Fb\",\n name: \"Stable Coin\",\n version: \"1\",\n decimals: 6,\n assetTransferMethod: \"permit2\",\n supportsEip2612: true,\n }, // Radius Testnet SBC (no EIP-3009, supports EIP-2612)\n \"eip155:36900\": {\n address: \"0x9cb8142aEBBcdc60AF7c97Af897A67A8f3CA71C2\",\n name: \"USDC.e\",\n version: \"2\",\n decimals: 6,\n }, // ADI Chain USDC.e (EIP-3009 supported)\n \"eip155:190415\": {\n address: \"0x401eCb1D350407f13ba348573E5630B83638E30D\",\n name: \"Bridged USDC\",\n version: \"2\",\n decimals: 6,\n }, // HPP mainnet USDC.e\n \"eip155:181228\": {\n address: \"0x401eCb1D350407f13ba348573E5630B83638E30D\",\n name: \"Bridged USDC\",\n version: \"2\",\n decimals: 6,\n }, // HPP Sepolia USDC.e\n \"eip155:50\": {\n address: \"0xfA2958CB79b0491CC627c1557F441eF849Ca8eb1\",\n name: \"USDC\",\n version: \"2\",\n decimals: 6,\n }, // XDC Network mainnet USDC (Bridged USDC Standard, EIP-3009 supported)\n \"eip155:51\": {\n address: \"0xb5AB69F7bBada22B28e79C8FFAECe55eF1c771D4\",\n name: \"USDC\",\n version: \"2\",\n decimals: 6,\n }, // XDC Apothem testnet USDC (Bridged USDC Standard, EIP-3009 supported)\n \"eip155:38833\": {\n address: \"0xA5b8BF902b2844dA17d4506cc827F7F1681735E7\",\n name: \"USDC\",\n version: \"1\",\n decimals: 6,\n assetTransferMethod: \"permit2\",\n }, // Igra mainnet USDC (no EIP-3009, no EIP-2612)\n \"eip155:14\": {\n address: \"0xe7cd86e13AC4309349F30B3435a9d337750fC82D\",\n name: \"USD\\u20AE0\",\n version: \"1\",\n decimals: 6,\n }, // Flare mainnet USD₮0 (EIP-3009 supported)\n \"eip155:42220\": {\n address: \"0xcebA9300f2b948710d2653dD7B07f33A8B32118C\",\n name: \"USDC\",\n version: \"2\",\n decimals: 6,\n }, // Celo mainnet USDC (EIP-3009 supported)\n \"eip155:11142220\": {\n address: \"0x01C5C0122039549AD1493B8220cABEdD739BC44E\",\n name: \"USDC\",\n version: \"2\",\n decimals: 6,\n }, // Celo Sepolia testnet USDC (EIP-3009 supported)\n};\n\n/**\n * Look up the default stablecoin for a network.\n *\n * @param network - CAIP-2 network identifier (e.g. \"eip155:8453\")\n * @returns The default asset info\n * @throws If no default asset is configured for the network\n */\nexport function getDefaultAsset(network: Network): ExactDefaultAssetInfo {\n const info = DEFAULT_STABLECOINS[network];\n if (!info) {\n throw new Error(`No default asset configured for network ${network}`);\n }\n return info;\n}\n","import { x402ResourceServer } from \"@x402/core/server\";\nimport { Network } from \"@x402/core/types\";\nimport { ExactEvmScheme } from \"./scheme\";\n\n/**\n * Configuration options for registering EVM schemes to an x402ResourceServer\n */\nexport interface EvmResourceServerConfig {\n /**\n * Optional specific networks to register\n * If not provided, registers wildcard support (eip155:*)\n */\n networks?: Network[];\n}\n\n/**\n * Registers EVM exact payment schemes to an x402ResourceServer instance.\n *\n * This function registers:\n * - V2: eip155:* wildcard scheme with ExactEvmScheme (or specific networks if provided)\n *\n * @param server - The x402ResourceServer instance to register schemes to\n * @param config - Configuration for EVM resource server registration\n * @returns The server instance for chaining\n *\n * @example\n * ```typescript\n * import { registerExactEvmScheme } from \"@x402/evm/exact/server/register\";\n * import { x402ResourceServer } from \"@x402/core/server\";\n *\n * const server = new x402ResourceServer(facilitatorClient);\n * registerExactEvmScheme(server, {});\n * ```\n */\nexport function registerExactEvmScheme(\n server: x402ResourceServer,\n config: EvmResourceServerConfig = {},\n): x402ResourceServer {\n // Register V2 scheme\n if (config.networks && config.networks.length > 0) {\n // Register specific networks\n config.networks.forEach(network => {\n server.register(network, new ExactEvmScheme());\n });\n } else {\n // Register wildcard for all EVM chains\n server.register(\"eip155:*\", new ExactEvmScheme());\n }\n\n return server;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACQA,mBAA8E;;;ACkCvE,IAAM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AuB,QAAQ,OAAO;AAAA,EACpD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAcA,2BACE,qBACA,eAMA,eAC8B;AAE9B,SAAK;AACL,SAAK;AACL,WAAO,QAAQ,QAAQ,mBAAmB;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASQ,oBAAoB,OAAgC;AAC1D,QAAI,OAAO,UAAU,UAAU;AAC7B,aAAO;AAAA,IACT;AAEA,eAAO,+BAAiB,KAAK;AAAA,EAC/B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASQ,uBAAuB,QAAgB,SAA+B;AAC5E,UAAM,YAAmC,gBAAgB,OAAO;AAChE,UAAM,kBAAc,uCAAqB,oCAAsB,MAAM,GAAG,UAAU,QAAQ;AAM1F,UAAM,sBAAsB,CAAC,UAAU,uBAAuB,UAAU;AAExE,WAAO;AAAA,MACL,QAAQ;AAAA,MACR,OAAO,UAAU;AAAA,MACjB,OAAO;AAAA,QACL,GAAI,uBAAuB;AAAA,UACzB,MAAM,UAAU;AAAA,UAChB,SAAS,UAAU;AAAA,QACrB;AAAA,QACA,GAAI,UAAU,uBAAuB;AAAA,UACnC,qBAAqB,UAAU;AAAA,QACjC;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;;;AEzIO,SAAS,uBACd,QACA,SAAkC,CAAC,GACf;AAEpB,MAAI,OAAO,YAAY,OAAO,SAAS,SAAS,GAAG;AAEjD,WAAO,SAAS,QAAQ,aAAW;AACjC,aAAO,SAAS,SAAS,IAAI,eAAe,CAAC;AAAA,IAC/C,CAAC;AAAA,EACH,OAAO;AAEL,WAAO,SAAS,YAAY,IAAI,eAAe,CAAC;AAAA,EAClD;AAEA,SAAO;AACT;","names":[]}
{"version":3,"sources":["../../../../src/exact/server/index.ts","../../../../src/exact/server/scheme.ts","../../../../src/shared/defaultAssets.ts","../../../../src/exact/server/register.ts"],"sourcesContent":["export { ExactEvmScheme } from \"./scheme\";\nexport { registerExactEvmScheme } from \"./register\";\nexport type { EvmResourceServerConfig } from \"./register\";\n","import {\n AssetAmount,\n Network,\n PaymentFlowConfig,\n PaymentRequirements,\n Price,\n SchemeNetworkServer,\n MoneyParser,\n} from \"@x402/core/types\";\nimport { convertToTokenAmount, numberToDecimalString, parseMoneyString } from \"@x402/core/utils\";\nimport { getDefaultAsset, type ExactDefaultAssetInfo } from \"../../shared/defaultAssets\";\nimport type { AssetTransferMethod } from \"../../types\";\n\n/**\n * EVM server implementation for the Exact payment scheme.\n */\nexport class ExactEvmScheme implements SchemeNetworkServer {\n readonly scheme = \"exact\";\n readonly defaultAssetTransferMethod: AssetTransferMethod = \"eip3009\";\n readonly paymentFlows = {\n eip3009: { supported: [\"authorization\"], default: \"authorization\" },\n permit2: { supported: [\"authorization\"], default: \"authorization\" },\n } as const satisfies Record<AssetTransferMethod, PaymentFlowConfig>;\n private moneyParsers: MoneyParser[] = [];\n\n /**\n * Register a custom money parser in the parser chain.\n * Multiple parsers can be registered - they will be tried in registration order.\n * Each parser receives a decimal amount (e.g., 1.50 for $1.50).\n * If a parser returns null, the next parser in the chain will be tried.\n * The default parser is always the final fallback.\n *\n * @param parser - Custom function to convert amount to AssetAmount (or null to skip)\n * @returns The server instance for chaining\n *\n * @example\n * evmServer.registerMoneyParser(async (amount, network) => {\n * // Custom conversion logic\n * if (amount > 100) {\n * // Use different token for large amounts\n * return { amount: (amount * 1e18).toString(), asset: \"0xCustomToken\" };\n * }\n * return null; // Use next parser\n * });\n */\n registerMoneyParser(parser: MoneyParser): ExactEvmScheme {\n this.moneyParsers.push(parser);\n return this;\n }\n\n /**\n * Returns the decimal precision of the default stablecoin for the given network.\n * Implements the optional AssetDecimalsProvider interface used by resolveSettlementOverrideAmount.\n *\n * @param _asset - The asset symbol (unused; defaults to the network's default stablecoin)\n * @param network - The network to look up the default asset for\n * @returns The number of decimal places for the asset\n */\n getAssetDecimals(_asset: string, network: Network): number {\n try {\n return getDefaultAsset(network).decimals;\n } catch {\n return 6;\n }\n }\n\n /**\n * Parses a price into an asset amount.\n * If price is already an AssetAmount, returns it directly.\n * If price is Money (string | number), parses to decimal and tries custom parsers.\n * Falls back to default conversion if all custom parsers return null.\n *\n * @param price - The price to parse\n * @param network - The network to use\n * @returns Promise that resolves to the parsed asset amount\n */\n async parsePrice(price: Price, network: Network): Promise<AssetAmount> {\n // If already an AssetAmount, return it directly\n if (typeof price === \"object\" && price !== null && \"amount\" in price) {\n if (!price.asset) {\n throw new Error(`Asset address must be specified for AssetAmount on network ${network}`);\n }\n return {\n amount: price.amount,\n asset: price.asset,\n extra: price.extra || {},\n };\n }\n\n // Parse Money to decimal number\n const amount = this.parseMoneyToDecimal(price);\n\n // Try each custom money parser in order\n for (const parser of this.moneyParsers) {\n const result = await parser(amount, network);\n if (result !== null) {\n return result;\n }\n }\n\n // All custom parsers returned null, use default conversion\n return this.defaultMoneyConversion(amount, network);\n }\n\n /**\n * Build payment requirements for this scheme/network combination\n *\n * @param paymentRequirements - The base payment requirements\n * @param supportedKind - The supported kind from facilitator (unused)\n * @param supportedKind.x402Version - The x402 version\n * @param supportedKind.scheme - The logical payment scheme\n * @param supportedKind.network - The network identifier in CAIP-2 format\n * @param supportedKind.extra - Optional extra metadata regarding scheme/network implementation details\n * @param extensionKeys - Extension keys supported by the facilitator (unused)\n * @returns Payment requirements ready to be sent to clients\n */\n enhancePaymentRequirements(\n paymentRequirements: PaymentRequirements,\n supportedKind: {\n x402Version: number;\n scheme: string;\n network: Network;\n extra?: Record<string, unknown>;\n },\n extensionKeys: string[],\n ): Promise<PaymentRequirements> {\n // Mark unused parameters to satisfy linter\n void supportedKind;\n void extensionKeys;\n return Promise.resolve(paymentRequirements);\n }\n\n /**\n * Parse Money (string | number) to a decimal number.\n * Handles formats like \"$1.50\", \"1.50\", 1.50, etc.\n *\n * @param money - The money value to parse\n * @returns Decimal number\n */\n private parseMoneyToDecimal(money: string | number): number {\n if (typeof money === \"number\") {\n return money;\n }\n\n return parseMoneyString(money);\n }\n\n /**\n * Converts a numeric dollar amount to an AssetAmount using the default token for the network.\n *\n * @param amount - The dollar amount as a number\n * @param network - The target network\n * @returns The converted asset amount with token metadata\n */\n private defaultMoneyConversion(amount: number, network: Network): AssetAmount {\n const assetInfo: ExactDefaultAssetInfo = getDefaultAsset(network);\n const tokenAmount = convertToTokenAmount(numberToDecimalString(amount), assetInfo.decimals);\n\n // EIP-3009 tokens always need name/version for their transferWithAuthorization domain.\n // Permit2 tokens only need them if the token supports EIP-2612 (for gasless permit signing).\n // Omitting name/version for permit2 tokens signals the client to skip EIP-2612 and use\n // ERC-20 approval gas sponsoring instead.\n const includeEip712Domain = !assetInfo.assetTransferMethod || assetInfo.supportsEip2612;\n\n return {\n amount: tokenAmount,\n asset: assetInfo.address,\n extra: {\n ...(includeEip712Domain && {\n name: assetInfo.name,\n version: assetInfo.version,\n }),\n ...(assetInfo.assetTransferMethod && {\n assetTransferMethod: assetInfo.assetTransferMethod,\n }),\n },\n };\n }\n}\n","import type { Network } from \"@x402/core/types\";\n\n/**\n * Base stablecoin asset configuration shared across all EVM payment schemes.\n * Contains the core fields needed to identify and convert tokens.\n */\nexport type DefaultAssetInfo = {\n /** Token contract address */\n address: string;\n /** EIP-712 domain name (must match the token's domain separator) */\n name: string;\n /** EIP-712 domain version (must match the token's domain separator) */\n version: string;\n /** Token decimal places (typically 6 for USDC) */\n decimals: number;\n};\n\n/**\n * Extended asset configuration for the exact scheme.\n * Includes transfer method hints that control client-side behaviour.\n */\nexport type ExactDefaultAssetInfo = DefaultAssetInfo & {\n /**\n * Transfer method override: `\"permit2\"` for tokens that don't support EIP-3009.\n * Omit for EIP-3009 tokens (default behaviour).\n */\n assetTransferMethod?: string;\n /**\n * Set to `true` for permit2 tokens that implement EIP-2612 `permit()`.\n * Controls whether name/version are included in `extra` so the client can\n * sign a gasless EIP-2612 permit for Permit2 approval.\n */\n supportsEip2612?: boolean;\n};\n\n/**\n * Default stablecoins indexed by CAIP-2 network identifier.\n *\n * Each network has the right to determine its own default stablecoin that can\n * be expressed as a USD string by calling servers. See DEFAULT_ASSETS.md at the\n * repository root for how to add new chains.\n */\nexport const DEFAULT_STABLECOINS: Record<string, ExactDefaultAssetInfo> = {\n \"eip155:8453\": {\n address: \"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913\",\n name: \"USD Coin\",\n version: \"2\",\n decimals: 6,\n }, // Base mainnet USDC\n \"eip155:84532\": {\n address: \"0x036CbD53842c5426634e7929541eC2318f3dCF7e\",\n name: \"USDC\",\n version: \"2\",\n decimals: 6,\n }, // Base Sepolia USDC\n \"eip155:4326\": {\n address: \"0xFAfDdbb3FC7688494971a79cc65DCa3EF82079E7\",\n name: \"MegaUSD\",\n version: \"1\",\n decimals: 18,\n assetTransferMethod: \"permit2\",\n supportsEip2612: true,\n }, // MegaETH mainnet MegaUSD (no EIP-3009, supports EIP-2612)\n \"eip155:143\": {\n address: \"0x754704Bc059F8C67012fEd69BC8A327a5aafb603\",\n name: \"USDC\",\n version: \"2\",\n decimals: 6,\n }, // Monad mainnet USDC\n \"eip155:988\": {\n address: \"0x779Ded0c9e1022225f8E0630b35a9b54bE713736\",\n name: \"USDT0\",\n version: \"1\",\n decimals: 6,\n }, // Stable mainnet USDT0\n \"eip155:2201\": {\n address: \"0x78Cf24370174180738C5B8E352B6D14c83a6c9A9\",\n name: \"USDT0\",\n version: \"1\",\n decimals: 6,\n }, // Stable testnet USDT0\n \"eip155:137\": {\n address: \"0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359\",\n name: \"USD Coin\",\n version: \"2\",\n decimals: 6,\n }, // Polygon mainnet USDC\n \"eip155:42161\": {\n address: \"0xaf88d065e77c8cC2239327C5EDb3A432268e5831\",\n name: \"USD Coin\",\n version: \"2\",\n decimals: 6,\n }, // Arbitrum One USDC\n \"eip155:421614\": {\n address: \"0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d\",\n name: \"USD Coin\",\n version: \"2\",\n decimals: 6,\n }, // Arbitrum Sepolia USDC\n \"eip155:31612\": {\n address: \"0xdD468A1DDc392dcdbEf6db6e34E89AA338F9F186\",\n name: \"Mezo USD\",\n version: \"1\",\n decimals: 18,\n assetTransferMethod: \"permit2\",\n supportsEip2612: true,\n }, // Mezo mainnet mUSD (no EIP-3009, supports EIP-2612)\n \"eip155:31611\": {\n address: \"0x118917a40FAF1CD7a13dB0Ef56C86De7973Ac503\",\n name: \"Mezo USD\",\n version: \"1\",\n decimals: 18,\n assetTransferMethod: \"permit2\",\n supportsEip2612: true,\n }, // Mezo Testnet mUSD (no EIP-3009, supports EIP-2612)\n \"eip155:723487\": {\n address: \"0x33ad9e4BD16B69B5BFdED37D8B5D9fF9aba014Fb\",\n name: \"Stable Coin\",\n version: \"1\",\n decimals: 6,\n assetTransferMethod: \"permit2\",\n supportsEip2612: true,\n }, // Radius Network SBC (no EIP-3009, supports EIP-2612)\n \"eip155:72344\": {\n address: \"0x33ad9e4BD16B69B5BFdED37D8B5D9fF9aba014Fb\",\n name: \"Stable Coin\",\n version: \"1\",\n decimals: 6,\n assetTransferMethod: \"permit2\",\n supportsEip2612: true,\n }, // Radius Testnet SBC (no EIP-3009, supports EIP-2612)\n \"eip155:36900\": {\n address: \"0x9cb8142aEBBcdc60AF7c97Af897A67A8f3CA71C2\",\n name: \"USDC.e\",\n version: \"2\",\n decimals: 6,\n }, // ADI Chain USDC.e (EIP-3009 supported)\n \"eip155:190415\": {\n address: \"0x401eCb1D350407f13ba348573E5630B83638E30D\",\n name: \"Bridged USDC\",\n version: \"2\",\n decimals: 6,\n }, // HPP mainnet USDC.e\n \"eip155:181228\": {\n address: \"0x401eCb1D350407f13ba348573E5630B83638E30D\",\n name: \"Bridged USDC\",\n version: \"2\",\n decimals: 6,\n }, // HPP Sepolia USDC.e\n \"eip155:50\": {\n address: \"0xfA2958CB79b0491CC627c1557F441eF849Ca8eb1\",\n name: \"USDC\",\n version: \"2\",\n decimals: 6,\n }, // XDC Network mainnet USDC (Bridged USDC Standard, EIP-3009 supported)\n \"eip155:51\": {\n address: \"0xb5AB69F7bBada22B28e79C8FFAECe55eF1c771D4\",\n name: \"USDC\",\n version: \"2\",\n decimals: 6,\n }, // XDC Apothem testnet USDC (Bridged USDC Standard, EIP-3009 supported)\n \"eip155:38833\": {\n address: \"0xA5b8BF902b2844dA17d4506cc827F7F1681735E7\",\n name: \"USDC\",\n version: \"1\",\n decimals: 6,\n assetTransferMethod: \"permit2\",\n }, // Igra mainnet USDC (no EIP-3009, no EIP-2612)\n \"eip155:14\": {\n address: \"0xe7cd86e13AC4309349F30B3435a9d337750fC82D\",\n name: \"USD\\u20AE0\",\n version: \"1\",\n decimals: 6,\n }, // Flare mainnet USD₮0 (EIP-3009 supported)\n \"eip155:42220\": {\n address: \"0xcebA9300f2b948710d2653dD7B07f33A8B32118C\",\n name: \"USDC\",\n version: \"2\",\n decimals: 6,\n }, // Celo mainnet USDC (EIP-3009 supported)\n \"eip155:11142220\": {\n address: \"0x01C5C0122039549AD1493B8220cABEdD739BC44E\",\n name: \"USDC\",\n version: \"2\",\n decimals: 6,\n }, // Celo Sepolia testnet USDC (EIP-3009 supported)\n};\n\n/**\n * Look up the default stablecoin for a network.\n *\n * @param network - CAIP-2 network identifier (e.g. \"eip155:8453\")\n * @returns The default asset info\n * @throws If no default asset is configured for the network\n */\nexport function getDefaultAsset(network: Network): ExactDefaultAssetInfo {\n const info = DEFAULT_STABLECOINS[network];\n if (!info) {\n throw new Error(`No default asset configured for network ${network}`);\n }\n return info;\n}\n","import { x402ResourceServer } from \"@x402/core/server\";\nimport { Network } from \"@x402/core/types\";\nimport { ExactEvmScheme } from \"./scheme\";\n\n/**\n * Configuration options for registering EVM schemes to an x402ResourceServer\n */\nexport interface EvmResourceServerConfig {\n /**\n * Optional specific networks to register\n * If not provided, registers wildcard support (eip155:*)\n */\n networks?: Network[];\n}\n\n/**\n * Registers EVM exact payment schemes to an x402ResourceServer instance.\n *\n * This function registers:\n * - V2: eip155:* wildcard scheme with ExactEvmScheme (or specific networks if provided)\n *\n * @param server - The x402ResourceServer instance to register schemes to\n * @param config - Configuration for EVM resource server registration\n * @returns The server instance for chaining\n *\n * @example\n * ```typescript\n * import { registerExactEvmScheme } from \"@x402/evm/exact/server/register\";\n * import { x402ResourceServer } from \"@x402/core/server\";\n *\n * const server = new x402ResourceServer(facilitatorClient);\n * registerExactEvmScheme(server, {});\n * ```\n */\nexport function registerExactEvmScheme(\n server: x402ResourceServer,\n config: EvmResourceServerConfig = {},\n): x402ResourceServer {\n // Register V2 scheme\n if (config.networks && config.networks.length > 0) {\n // Register specific networks\n config.networks.forEach(network => {\n server.register(network, new ExactEvmScheme());\n });\n } else {\n // Register wildcard for all EVM chains\n server.register(\"eip155:*\", new ExactEvmScheme());\n }\n\n return server;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACSA,mBAA8E;;;ACiCvE,IAAM,sBAA6D;AAAA,EACxE,eAAe;AAAA,IACb,SAAS;AAAA,IACT,MAAM;AAAA,IACN,SAAS;AAAA,IACT,UAAU;AAAA,EACZ;AAAA;AAAA,EACA,gBAAgB;AAAA,IACd,SAAS;AAAA,IACT,MAAM;AAAA,IACN,SAAS;AAAA,IACT,UAAU;AAAA,EACZ;AAAA;AAAA,EACA,eAAe;AAAA,IACb,SAAS;AAAA,IACT,MAAM;AAAA,IACN,SAAS;AAAA,IACT,UAAU;AAAA,IACV,qBAAqB;AAAA,IACrB,iBAAiB;AAAA,EACnB;AAAA;AAAA,EACA,cAAc;AAAA,IACZ,SAAS;AAAA,IACT,MAAM;AAAA,IACN,SAAS;AAAA,IACT,UAAU;AAAA,EACZ;AAAA;AAAA,EACA,cAAc;AAAA,IACZ,SAAS;AAAA,IACT,MAAM;AAAA,IACN,SAAS;AAAA,IACT,UAAU;AAAA,EACZ;AAAA;AAAA,EACA,eAAe;AAAA,IACb,SAAS;AAAA,IACT,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B,QAAgB,SAA+B;AAC5E,UAAM,YAAmC,gBAAgB,OAAO;AAChE,UAAM,kBAAc,uCAAqB,oCAAsB,MAAM,GAAG,UAAU,QAAQ;AAM1F,UAAM,sBAAsB,CAAC,UAAU,uBAAuB,UAAU;AAExE,WAAO;AAAA,MACL,QAAQ;AAAA,MACR,OAAO,UAAU;AAAA,MACjB,OAAO;AAAA,QACL,GAAI,uBAAuB;AAAA,UACzB,MAAM,UAAU;AAAA,UAChB,SAAS,UAAU;AAAA,QACrB;AAAA,QACA,GAAI,UAAU,uBAAuB;AAAA,UACnC,qBAAqB,UAAU;AAAA,QACjC;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;;;AEhJO,SAAS,uBACd,QACA,SAAkC,CAAC,GACf;AAEpB,MAAI,OAAO,YAAY,OAAO,SAAS,SAAS,GAAG;AAEjD,WAAO,SAAS,QAAQ,aAAW;AACjC,aAAO,SAAS,SAAS,IAAI,eAAe,CAAC;AAAA,IAC/C,CAAC;AAAA,EACH,OAAO;AAEL,WAAO,SAAS,YAAY,IAAI,eAAe,CAAC;AAAA,EAClD;AAEA,SAAO;AACT;","names":[]}

@@ -5,5 +5,7 @@ export { E as ExactEvmScheme } from './scheme-DbvdjMb_.js';

export { a as PERMIT2_ADDRESS, P as Permit2AllowanceParams, d as authorizationTypes, c as createPermit2ApprovalTx, f as eip3009ABI, e as erc20AllowanceAbi, g as getPermit2AllowanceReadParams, p as permit2WitnessTypes, u as uptoPermit2WitnessTypes, h as x402ExactPermit2ProxyABI, x as x402ExactPermit2ProxyAddress, i as x402UptoPermit2ProxyABI, b as x402UptoPermit2ProxyAddress } from './permit2-DhJRUcgY.js';
import { A as AssetTransferMethod } from './types-BBC1mC8d.js';
export { E as ExactEIP3009Payload, b as ExactEvmPayloadV1, c as ExactEvmPayloadV2, a as ExactPermit2Payload, d as Permit2Authorization, P as Permit2Witness, g as UptoPermit2Authorization, U as UptoPermit2Payload, f as UptoPermit2Witness, e as isEIP3009Payload, i as isPermit2Payload, h as isUptoPermit2Payload } from './types-BBC1mC8d.js';
export { UptoEvmScheme } from './upto/client/index.js';
export { a as BatchSettlementEvmScheme } from './scheme-B-ZpMjZp.js';
export { A as AuthorizerSigner, i as BatchSettlementClaimPayload, e as BatchSettlementDepositPayload, j as BatchSettlementEnrichedRefundPayload, h as BatchSettlementErc3009Authorization, m as BatchSettlementFacilitatorSettlePayload, k as BatchSettlementPayload, n as BatchSettlementPaymentRequirementsExtra, o as BatchSettlementPaymentResponseExtra, g as BatchSettlementRefundPayload, l as BatchSettlementSettlePayload, B as BatchSettlementVoucherClaim, a as BatchSettlementVoucherFields, f as BatchSettlementVoucherPayload, C as ChannelConfig, d as ChannelState, s as isBatchSettlementClaimPayload, p as isBatchSettlementDepositPayload, u as isBatchSettlementEnrichedRefundPayload, r as isBatchSettlementRefundPayload, t as isBatchSettlementSettlePayload, q as isBatchSettlementVoucherPayload } from './types-DIt9uAUy.js';
export { a as BatchSettlementEvmScheme } from './scheme-C41SfdnU.js';
export { A as AuthorizerSigner, j as BatchSettlementClaimPayload, f as BatchSettlementDepositPayload, k as BatchSettlementEnrichedRefundPayload, i as BatchSettlementErc3009Authorization, n as BatchSettlementFacilitatorSettlePayload, l as BatchSettlementPayload, o as BatchSettlementPaymentRequirementsExtra, p as BatchSettlementPaymentResponseExtra, h as BatchSettlementRefundPayload, m as BatchSettlementSettlePayload, B as BatchSettlementVoucherClaim, b as BatchSettlementVoucherFields, g as BatchSettlementVoucherPayload, C as ChannelConfig, e as ChannelState, t as isBatchSettlementClaimPayload, q as isBatchSettlementDepositPayload, v as isBatchSettlementEnrichedRefundPayload, s as isBatchSettlementRefundPayload, u as isBatchSettlementSettlePayload, r as isBatchSettlementVoucherPayload } from './types-B4ib_1f_.js';
import { Network, FacilitatorContext, PaymentPayload, PaymentRequirements, FacilitatorExtension } from '@x402/core/types';

@@ -15,108 +17,2 @@ import { Hex, TypedDataDomain } from 'viem';

/**
* Asset transfer methods for the exact EVM scheme.
* - eip3009: Uses transferWithAuthorization (USDC, etc.) - recommended for compatible tokens
* - permit2: Uses Permit2 + x402Permit2Proxy - universal fallback for any ERC-20
*/
type AssetTransferMethod = "eip3009" | "permit2";
/**
* EIP-3009 payload for tokens with native transferWithAuthorization support.
*/
type ExactEIP3009Payload = {
signature?: `0x${string}`;
authorization: {
from: `0x${string}`;
to: `0x${string}`;
value: string;
validAfter: string;
validBefore: string;
nonce: `0x${string}`;
};
};
/**
* Permit2 witness data structure.
* Matches the Witness struct in x402Permit2Proxy contract.
* Note: Upper time bound is enforced by Permit2's `deadline` field, not a witness field.
*/
type Permit2Witness = {
to: `0x${string}`;
validAfter: string;
};
/**
* Permit2 authorization parameters.
* Used to reconstruct the signed message for verification.
*/
type Permit2Authorization = {
permitted: {
token: `0x${string}`;
amount: string;
};
spender: `0x${string}`;
nonce: string;
deadline: string;
witness: Permit2Witness;
};
/**
* Permit2 payload for tokens using the Permit2 + x402Permit2Proxy flow.
*/
type ExactPermit2Payload = {
signature: `0x${string}`;
permit2Authorization: Permit2Authorization & {
from: `0x${string}`;
};
};
type ExactEvmPayloadV1 = ExactEIP3009Payload;
type ExactEvmPayloadV2 = ExactEIP3009Payload | ExactPermit2Payload;
/**
* Type guard to check if a payload is a Permit2 payload.
* Permit2 payloads have a `permit2Authorization` field.
*
* @param payload - The payload to check.
* @returns True if the payload is a Permit2 payload, false otherwise.
*/
declare function isPermit2Payload(payload: ExactEvmPayloadV2): payload is ExactPermit2Payload;
/**
* Type guard to check if a payload is an EIP-3009 payload.
* EIP-3009 payloads have an `authorization` field.
*
* @param payload - The payload to check.
* @returns True if the payload is an EIP-3009 payload, false otherwise.
*/
declare function isEIP3009Payload(payload: ExactEvmPayloadV2): payload is ExactEIP3009Payload;
/**
* Upto Permit2 witness — includes `facilitator` field absent from exact witness.
* Only the address matching `witness.facilitator` can call settle() on-chain.
*/
type UptoPermit2Witness = {
to: `0x${string}`;
facilitator: `0x${string}`;
validAfter: string;
};
type UptoPermit2Authorization = {
permitted: {
token: `0x${string}`;
amount: string;
};
spender: `0x${string}`;
nonce: string;
deadline: string;
witness: UptoPermit2Witness;
};
type UptoPermit2Payload = {
signature: `0x${string}`;
permit2Authorization: UptoPermit2Authorization & {
from: `0x${string}`;
};
};
/**
* Type guard to check if a payload is an upto Permit2 payload.
* Validates structural presence of all required fields: signature, permit2Authorization
* (with from, permitted, spender, nonce, deadline), and a witness containing facilitator.
*
* @param payload - The payload to check.
* @returns True if the payload is an upto Permit2 payload, false otherwise.
*/
declare function isUptoPermit2Payload(payload: Record<string, unknown>): payload is UptoPermit2Payload;
/** Scheme identifier for the batch-settlement payment scheme. */

@@ -452,2 +348,2 @@ declare const BATCH_SETTLEMENT_SCHEME: "batch-settlement";

export { AUTH_CAPTURE_ESCROW_ADDRESS, AUTH_CAPTURE_SCHEME, type AssetTransferMethod, type Eip3009Payload as AuthCaptureEip3009Payload, type AuthCaptureExtra, type AuthCapturePayload, type PaymentInfoStruct as AuthCapturePaymentInfo, type Permit2Payload as AuthCapturePermit2Payload, BATCH_SETTLEMENT_ADDRESS, BATCH_SETTLEMENT_DOMAIN, BATCH_SETTLEMENT_SCHEME, BUILDER_CODE_KEY, type BuilderCodeFacilitatorExtension, DEFAULT_STABLECOINS, type DataSuffixContext, type DefaultAssetInfo, EIP3009_TOKEN_COLLECTOR_ADDRESS, ERC3009_DEPOSIT_COLLECTOR_ADDRESS, type Erc6492Classification, type ExactDefaultAssetInfo, type ExactEIP3009Payload, type ExactEvmPayloadV1, type ExactEvmPayloadV2, type ExactPermit2Payload, FacilitatorEvmSigner, PERMIT2_TOKEN_COLLECTOR_ADDRESS, type Permit2Authorization, type Permit2Witness, type UptoPermit2Authorization, type UptoPermit2Payload, type UptoPermit2Witness, appendDataSuffix, claimBatchTypes, classifyErc6492Payer, getDefaultAsset, getERC7702DelegateAddress, isAuthCaptureExtra, isAuthCapturePayload, isEIP3009Payload, isERC7702Delegation, isPermit2Payload, isUptoPermit2Payload, refundTypes, resolveDataSuffix, verifyHashSignature, verifyHashSignatureWithCode, verifyTypedDataSignature, voucherTypes };
export { AUTH_CAPTURE_ESCROW_ADDRESS, AUTH_CAPTURE_SCHEME, AssetTransferMethod, type Eip3009Payload as AuthCaptureEip3009Payload, type AuthCaptureExtra, type AuthCapturePayload, type PaymentInfoStruct as AuthCapturePaymentInfo, type Permit2Payload as AuthCapturePermit2Payload, BATCH_SETTLEMENT_ADDRESS, BATCH_SETTLEMENT_DOMAIN, BATCH_SETTLEMENT_SCHEME, BUILDER_CODE_KEY, type BuilderCodeFacilitatorExtension, DEFAULT_STABLECOINS, type DataSuffixContext, type DefaultAssetInfo, EIP3009_TOKEN_COLLECTOR_ADDRESS, ERC3009_DEPOSIT_COLLECTOR_ADDRESS, type Erc6492Classification, type ExactDefaultAssetInfo, FacilitatorEvmSigner, PERMIT2_TOKEN_COLLECTOR_ADDRESS, appendDataSuffix, claimBatchTypes, classifyErc6492Payer, getDefaultAsset, getERC7702DelegateAddress, isAuthCaptureExtra, isAuthCapturePayload, isERC7702Delegation, refundTypes, resolveDataSuffix, verifyHashSignature, verifyHashSignatureWithCode, verifyTypedDataSignature, voucherTypes };
import { SchemeNetworkServer, MoneyParser, Network, Price, AssetAmount, PaymentRequirements } from '@x402/core/types';
import { A as AssetTransferMethod } from '../../types-BBC1mC8d.js';

@@ -9,2 +10,9 @@ /**

readonly scheme = "upto";
readonly defaultAssetTransferMethod: AssetTransferMethod;
readonly paymentFlows: {
readonly permit2: {
readonly supported: readonly ["authorization"];
readonly default: "authorization";
};
};
private moneyParsers;

@@ -11,0 +19,0 @@ /**

@@ -58,3 +58,3 @@ "use strict";

address: "0x754704Bc059F8C67012fEd69BC8A327a5aafb603",
name: "USD Coin",
name: "USDC",
version: "2",

@@ -212,2 +212,6 @@ decimals: 6

this.scheme = "upto";
this.defaultAssetTransferMethod = "permit2";
this.paymentFlows = {
permit2: { supported: ["authorization"], default: "authorization" }
};
this.moneyParsers = [];

@@ -214,0 +218,0 @@ }

@@ -1,1 +0,1 @@

{"version":3,"sources":["../../../../src/upto/server/index.ts","../../../../src/upto/server/scheme.ts","../../../../src/shared/defaultAssets.ts"],"sourcesContent":["// Note: No register.ts helper — V1 backward compatibility is not needed for upto.\n// Use direct class instantiation: server.register(\"eip155:*\", new UptoEvmScheme())\nexport { UptoEvmScheme } from \"./scheme\";\n","import {\n AssetAmount,\n Network,\n PaymentRequirements,\n Price,\n SchemeNetworkServer,\n MoneyParser,\n} from \"@x402/core/types\";\nimport { convertToTokenAmount, numberToDecimalString, parseMoneyString } from \"@x402/core/utils\";\nimport { getAddress } from \"viem\";\nimport { getDefaultAsset } from \"../../shared/defaultAssets\";\n\n/**\n * EVM server implementation for the Upto payment scheme.\n * Handles price parsing, payment requirements enhancement, and default asset resolution.\n */\nexport class UptoEvmScheme implements SchemeNetworkServer {\n readonly scheme = \"upto\";\n private moneyParsers: MoneyParser[] = [];\n\n /**\n * Registers a custom money parser for converting prices to asset amounts.\n *\n * @param parser - The money parser function to register\n * @returns This instance for chaining\n */\n registerMoneyParser(parser: MoneyParser): UptoEvmScheme {\n this.moneyParsers.push(parser);\n return this;\n }\n\n /**\n * Returns the decimal precision of the default stablecoin for the given network.\n * Implements the optional AssetDecimalsProvider interface used by resolveSettlementOverrideAmount.\n *\n * @param _asset - The asset symbol (unused; defaults to the network's default stablecoin)\n * @param network - The network to look up the default asset for\n * @returns The number of decimal places for the asset\n */\n getAssetDecimals(_asset: string, network: Network): number {\n try {\n return getDefaultAsset(network).decimals;\n } catch {\n return 6;\n }\n }\n\n /**\n * Parses a price into an asset amount for the given network.\n *\n * @param price - The price to parse (string, number, or AssetAmount)\n * @param network - The target network\n * @returns Promise resolving to an asset amount\n */\n async parsePrice(price: Price, network: Network): Promise<AssetAmount> {\n if (typeof price === \"object\" && price !== null && \"amount\" in price) {\n if (!price.asset) {\n throw new Error(`Asset address must be specified for AssetAmount on network ${network}`);\n }\n return {\n amount: price.amount,\n asset: price.asset,\n extra: price.extra || {},\n };\n }\n\n const amount = this.parseMoneyToDecimal(price);\n\n for (const parser of this.moneyParsers) {\n const result = await parser(amount, network);\n if (result !== null) {\n return result;\n }\n }\n\n return this.defaultMoneyConversion(amount, network);\n }\n\n /**\n * Enhances payment requirements with upto-specific metadata.\n *\n * @param paymentRequirements - The base payment requirements\n * @param supportedKind - The supported scheme/network kind\n * @param supportedKind.x402Version - The x402 protocol version\n * @param supportedKind.scheme - The payment scheme name\n * @param supportedKind.network - The target network\n * @param supportedKind.extra - Optional extra metadata\n * @param extensionKeys - Extension keys to include\n * @returns Promise resolving to enhanced payment requirements\n */\n enhancePaymentRequirements(\n paymentRequirements: PaymentRequirements,\n supportedKind: {\n x402Version: number;\n scheme: string;\n network: Network;\n extra?: Record<string, unknown>;\n },\n extensionKeys: string[],\n ): Promise<PaymentRequirements> {\n void extensionKeys;\n return Promise.resolve({\n ...paymentRequirements,\n extra: {\n ...paymentRequirements.extra,\n assetTransferMethod: \"permit2\",\n ...(supportedKind.extra?.facilitatorAddress\n ? { facilitatorAddress: getAddress(supportedKind.extra.facilitatorAddress as string) }\n : {}),\n },\n });\n }\n\n /**\n * Parses a money string or number into a decimal value.\n *\n * @param money - The money value to parse\n * @returns The parsed decimal amount\n */\n private parseMoneyToDecimal(money: string | number): number {\n if (typeof money === \"number\") {\n return money;\n }\n\n return parseMoneyString(money);\n }\n\n /**\n * Converts a numeric dollar amount to an AssetAmount using the default token for the network.\n *\n * @param amount - The dollar amount as a number\n * @param network - The target network\n * @returns The converted asset amount with token metadata\n */\n private defaultMoneyConversion(amount: number, network: Network): AssetAmount {\n const assetInfo = getDefaultAsset(network);\n const tokenAmount = convertToTokenAmount(numberToDecimalString(amount), assetInfo.decimals);\n\n return {\n amount: tokenAmount,\n asset: assetInfo.address,\n extra: {\n name: assetInfo.name,\n version: assetInfo.version,\n assetTransferMethod: \"permit2\",\n },\n };\n }\n}\n","import type { Network } from \"@x402/core/types\";\n\n/**\n * Base stablecoin asset configuration shared across all EVM payment schemes.\n * Contains the core fields needed to identify and convert tokens.\n */\nexport type DefaultAssetInfo = {\n /** Token contract address */\n address: string;\n /** EIP-712 domain name (must match the token's domain separator) */\n name: string;\n /** EIP-712 domain version (must match the token's domain separator) */\n version: string;\n /** Token decimal places (typically 6 for USDC) */\n decimals: number;\n};\n\n/**\n * Extended asset configuration for the exact scheme.\n * Includes transfer method hints that control client-side behaviour.\n */\nexport type ExactDefaultAssetInfo = DefaultAssetInfo & {\n /**\n * Transfer method override: `\"permit2\"` for tokens that don't support EIP-3009.\n * Omit for EIP-3009 tokens (default behaviour).\n */\n assetTransferMethod?: string;\n /**\n * Set to `true` for permit2 tokens that implement EIP-2612 `permit()`.\n * Controls whether name/version are included in `extra` so the client can\n * sign a gasless EIP-2612 permit for Permit2 approval.\n */\n supportsEip2612?: boolean;\n};\n\n/**\n * Default stablecoins indexed by CAIP-2 network identifier.\n *\n * Each network has the right to determine its own default stablecoin that can\n * be expressed as a USD string by calling servers. See DEFAULT_ASSETS.md at the\n * repository root for how to add new chains.\n */\nexport const DEFAULT_STABLECOINS: Record<string, ExactDefaultAssetInfo> = {\n \"eip155:8453\": {\n address: \"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913\",\n name: \"USD Coin\",\n version: \"2\",\n decimals: 6,\n }, // Base mainnet USDC\n \"eip155:84532\": {\n address: \"0x036CbD53842c5426634e7929541eC2318f3dCF7e\",\n name: \"USDC\",\n version: \"2\",\n decimals: 6,\n }, // Base Sepolia USDC\n \"eip155:4326\": {\n address: \"0xFAfDdbb3FC7688494971a79cc65DCa3EF82079E7\",\n name: \"MegaUSD\",\n version: \"1\",\n decimals: 18,\n assetTransferMethod: \"permit2\",\n supportsEip2612: true,\n }, // MegaETH mainnet MegaUSD (no EIP-3009, supports EIP-2612)\n \"eip155:143\": {\n address: \"0x754704Bc059F8C67012fEd69BC8A327a5aafb603\",\n name: \"USD Coin\",\n version: \"2\",\n decimals: 6,\n }, // Monad mainnet USDC\n \"eip155:988\": {\n address: \"0x779Ded0c9e1022225f8E0630b35a9b54bE713736\",\n name: \"USDT0\",\n version: \"1\",\n decimals: 6,\n }, // Stable mainnet USDT0\n \"eip155:2201\": {\n address: \"0x78Cf24370174180738C5B8E352B6D14c83a6c9A9\",\n name: \"USDT0\",\n version: \"1\",\n decimals: 6,\n }, // Stable testnet USDT0\n \"eip155:137\": {\n address: \"0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359\",\n name: \"USD Coin\",\n version: \"2\",\n decimals: 6,\n }, // Polygon mainnet USDC\n \"eip155:42161\": {\n address: \"0xaf88d065e77c8cC2239327C5EDb3A432268e5831\",\n name: \"USD Coin\",\n version: \"2\",\n decimals: 6,\n }, // Arbitrum One USDC\n \"eip155:421614\": {\n address: \"0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d\",\n name: \"USD Coin\",\n version: \"2\",\n decimals: 6,\n }, // Arbitrum Sepolia USDC\n \"eip155:31612\": {\n address: \"0xdD468A1DDc392dcdbEf6db6e34E89AA338F9F186\",\n name: \"Mezo USD\",\n version: \"1\",\n decimals: 18,\n assetTransferMethod: \"permit2\",\n supportsEip2612: true,\n }, // Mezo mainnet mUSD (no EIP-3009, supports EIP-2612)\n \"eip155:31611\": {\n address: \"0x118917a40FAF1CD7a13dB0Ef56C86De7973Ac503\",\n name: \"Mezo USD\",\n version: \"1\",\n decimals: 18,\n assetTransferMethod: \"permit2\",\n supportsEip2612: true,\n }, // Mezo Testnet mUSD (no EIP-3009, supports EIP-2612)\n \"eip155:723487\": {\n address: \"0x33ad9e4BD16B69B5BFdED37D8B5D9fF9aba014Fb\",\n name: \"Stable Coin\",\n version: \"1\",\n decimals: 6,\n assetTransferMethod: \"permit2\",\n supportsEip2612: true,\n }, // Radius Network SBC (no EIP-3009, supports EIP-2612)\n \"eip155:72344\": {\n address: \"0x33ad9e4BD16B69B5BFdED37D8B5D9fF9aba014Fb\",\n name: \"Stable Coin\",\n version: \"1\",\n decimals: 6,\n assetTransferMethod: \"permit2\",\n supportsEip2612: true,\n }, // Radius Testnet SBC (no EIP-3009, supports EIP-2612)\n \"eip155:36900\": {\n address: \"0x9cb8142aEBBcdc60AF7c97Af897A67A8f3CA71C2\",\n name: \"USDC.e\",\n version: \"2\",\n decimals: 6,\n }, // ADI Chain USDC.e (EIP-3009 supported)\n \"eip155:190415\": {\n address: \"0x401eCb1D350407f13ba348573E5630B83638E30D\",\n name: \"Bridged USDC\",\n version: \"2\",\n decimals: 6,\n }, // HPP mainnet USDC.e\n \"eip155:181228\": {\n address: \"0x401eCb1D350407f13ba348573E5630B83638E30D\",\n name: \"Bridged USDC\",\n version: \"2\",\n decimals: 6,\n }, // HPP Sepolia USDC.e\n \"eip155:50\": {\n address: \"0xfA2958CB79b0491CC627c1557F441eF849Ca8eb1\",\n name: \"USDC\",\n version: \"2\",\n decimals: 6,\n }, // XDC Network mainnet USDC (Bridged USDC Standard, EIP-3009 supported)\n \"eip155:51\": {\n address: \"0xb5AB69F7bBada22B28e79C8FFAECe55eF1c771D4\",\n name: \"USDC\",\n version: \"2\",\n decimals: 6,\n }, // XDC Apothem testnet USDC (Bridged USDC Standard, EIP-3009 supported)\n \"eip155:38833\": {\n address: \"0xA5b8BF902b2844dA17d4506cc827F7F1681735E7\",\n name: \"USDC\",\n version: \"1\",\n decimals: 6,\n assetTransferMethod: \"permit2\",\n }, // Igra mainnet USDC (no EIP-3009, no EIP-2612)\n \"eip155:14\": {\n address: \"0xe7cd86e13AC4309349F30B3435a9d337750fC82D\",\n name: \"USD\\u20AE0\",\n version: \"1\",\n decimals: 6,\n }, // Flare mainnet USD₮0 (EIP-3009 supported)\n \"eip155:42220\": {\n address: \"0xcebA9300f2b948710d2653dD7B07f33A8B32118C\",\n name: \"USDC\",\n version: \"2\",\n decimals: 6,\n }, // Celo mainnet USDC (EIP-3009 supported)\n \"eip155:11142220\": {\n address: \"0x01C5C0122039549AD1493B8220cABEdD739BC44E\",\n name: \"USDC\",\n version: \"2\",\n decimals: 6,\n }, // Celo Sepolia testnet USDC (EIP-3009 supported)\n};\n\n/**\n * Look up the default stablecoin for a network.\n *\n * @param network - CAIP-2 network identifier (e.g. \"eip155:8453\")\n * @returns The default asset info\n * @throws If no default asset is configured for the network\n */\nexport function getDefaultAsset(network: Network): ExactDefaultAssetInfo {\n const info = DEFAULT_STABLECOINS[network];\n if (!info) {\n throw new Error(`No default asset configured for network ${network}`);\n }\n return info;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACQA,mBAA8E;AAC9E,kBAA2B;;;ACiCpB,IAAM,sBAA6D;AAAA,EACxE,eAAe;AAAA,IACb,SAAS;AAAA,IACT,MAAM;AAAA,IACN,SAAS;AAAA,IACT,UAAU;AAAA,EACZ;AAAA;AAAA,EACA,gBAAgB;AAAA,IACd,SAAS;AAAA,IACT,MAAM;AAAA,IACN,SAAS;AAAA,IACT,UAAU;AAAA,EACZ;AAAA;AAAA,EACA,eAAe;AAAA,IACb,SAAS;AAAA,IACT,MAAM;AAAA,IACN,SAAS;AAAA,IACT,UAAU;AAAA,IACV,qBAAqB;AAAA,IACrB,iBAAiB;AAAA,EACnB;AAAA;AAAA,EACA,cAAc;AAAA,IACZ,SAAS;AAAA,IACT,MAAM;AAAA,IACN,SAAS;AAAA,IACT,UAAU;AAAA,EACZ;AAAA;AAAA,EACA,cAAc;AAAA,IACZ,SAAS;AAAA,IACT,MAAM;AAAA,IACN,SAAS;AAAA,IACT,UAAU;AAAA,EACZ;AAAA;AAAA,EACA,eAAe;AAAA,IACb,SAAS;AAAA,IACT,MAAM;AAAA,IACN,SAAS;AAAA,IACT,UAAU;AAAA,EACZ;AAAA;AAAA,EACA,cAAc;AAAA,IACZ,SAAS;AAAA,IACT,MAAM;AAAA,IACN,SAAS;AAAA,IACT,UAAU;AAAA,EACZ;AAAA;AAAA,EACA,gBAAgB;AAAA,IACd,SAAS;AAAA,IACT,MAAM;AAAA,IACN,SAAS;AAAA,IACT,UAAU;AAAA,EACZ;AAAA;AAAA,EACA,iBAAiB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AAM,SAAS,CAAC;AAAA,MACzB;AAAA,IACF;AAEA,UAAM,SAAS,KAAK,oBAAoB,KAAK;AAE7C,eAAW,UAAU,KAAK,cAAc;AACtC,YAAM,SAAS,MAAM,OAAO,QAAQ,OAAO;AAC3C,UAAI,WAAW,MAAM;AACnB,eAAO;AAAA,MACT;AAAA,IACF;AAEA,WAAO,KAAK,uBAAuB,QAAQ,OAAO;AAAA,EACpD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAcA,2BACE,qBACA,eAMA,eAC8B;AAC9B,SAAK;AACL,WAAO,QAAQ,QAAQ;AAAA,MACrB,GAAG;AAAA,MACH,OAAO;AAAA,QACL,GAAG,oBAAoB;AAAA,QACvB,qBAAqB;AAAA,QACrB,GAAI,cAAc,OAAO,qBACrB,EAAE,wBAAoB,wBAAW,cAAc,MAAM,kBAA4B,EAAE,IACnF,CAAC;AAAA,MACP;AAAA,IACF,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQQ,oBAAoB,OAAgC;AAC1D,QAAI,OAAO,UAAU,UAAU;AAC7B,aAAO;AAAA,IACT;AAEA,eAAO,+BAAiB,KAAK;AAAA,EAC/B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASQ,uBAAuB,QAAgB,SAA+B;AAC5E,UAAM,YAAY,gBAAgB,OAAO;AACzC,UAAM,kBAAc,uCAAqB,oCAAsB,MAAM,GAAG,UAAU,QAAQ;AAE1F,WAAO;AAAA,MACL,QAAQ;AAAA,MACR,OAAO,UAAU;AAAA,MACjB,OAAO;AAAA,QACL,MAAM,UAAU;AAAA,QAChB,SAAS,UAAU;AAAA,QACnB,qBAAqB;AAAA,MACvB;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
{"version":3,"sources":["../../../../src/upto/server/index.ts","../../../../src/upto/server/scheme.ts","../../../../src/shared/defaultAssets.ts"],"sourcesContent":["// Note: No register.ts helper — V1 backward compatibility is not needed for upto.\n// Use direct class instantiation: server.register(\"eip155:*\", new UptoEvmScheme())\nexport { UptoEvmScheme } from \"./scheme\";\n","import {\n AssetAmount,\n Network,\n PaymentFlowConfig,\n PaymentRequirements,\n Price,\n SchemeNetworkServer,\n MoneyParser,\n} from \"@x402/core/types\";\nimport { convertToTokenAmount, numberToDecimalString, parseMoneyString } from \"@x402/core/utils\";\nimport { getAddress } from \"viem\";\nimport { getDefaultAsset } from \"../../shared/defaultAssets\";\nimport type { AssetTransferMethod } from \"../../types\";\n\n/**\n * EVM server implementation for the Upto payment scheme.\n * Handles price parsing, payment requirements enhancement, and default asset resolution.\n */\nexport class UptoEvmScheme implements SchemeNetworkServer {\n readonly scheme = \"upto\";\n readonly defaultAssetTransferMethod: AssetTransferMethod = \"permit2\";\n readonly paymentFlows = {\n permit2: { supported: [\"authorization\"], default: \"authorization\" },\n } as const satisfies Record<\"permit2\", PaymentFlowConfig>;\n private moneyParsers: MoneyParser[] = [];\n\n /**\n * Registers a custom money parser for converting prices to asset amounts.\n *\n * @param parser - The money parser function to register\n * @returns This instance for chaining\n */\n registerMoneyParser(parser: MoneyParser): UptoEvmScheme {\n this.moneyParsers.push(parser);\n return this;\n }\n\n /**\n * Returns the decimal precision of the default stablecoin for the given network.\n * Implements the optional AssetDecimalsProvider interface used by resolveSettlementOverrideAmount.\n *\n * @param _asset - The asset symbol (unused; defaults to the network's default stablecoin)\n * @param network - The network to look up the default asset for\n * @returns The number of decimal places for the asset\n */\n getAssetDecimals(_asset: string, network: Network): number {\n try {\n return getDefaultAsset(network).decimals;\n } catch {\n return 6;\n }\n }\n\n /**\n * Parses a price into an asset amount for the given network.\n *\n * @param price - The price to parse (string, number, or AssetAmount)\n * @param network - The target network\n * @returns Promise resolving to an asset amount\n */\n async parsePrice(price: Price, network: Network): Promise<AssetAmount> {\n if (typeof price === \"object\" && price !== null && \"amount\" in price) {\n if (!price.asset) {\n throw new Error(`Asset address must be specified for AssetAmount on network ${network}`);\n }\n return {\n amount: price.amount,\n asset: price.asset,\n extra: price.extra || {},\n };\n }\n\n const amount = this.parseMoneyToDecimal(price);\n\n for (const parser of this.moneyParsers) {\n const result = await parser(amount, network);\n if (result !== null) {\n return result;\n }\n }\n\n return this.defaultMoneyConversion(amount, network);\n }\n\n /**\n * Enhances payment requirements with upto-specific metadata.\n *\n * @param paymentRequirements - The base payment requirements\n * @param supportedKind - The supported scheme/network kind\n * @param supportedKind.x402Version - The x402 protocol version\n * @param supportedKind.scheme - The payment scheme name\n * @param supportedKind.network - The target network\n * @param supportedKind.extra - Optional extra metadata\n * @param extensionKeys - Extension keys to include\n * @returns Promise resolving to enhanced payment requirements\n */\n enhancePaymentRequirements(\n paymentRequirements: PaymentRequirements,\n supportedKind: {\n x402Version: number;\n scheme: string;\n network: Network;\n extra?: Record<string, unknown>;\n },\n extensionKeys: string[],\n ): Promise<PaymentRequirements> {\n void extensionKeys;\n return Promise.resolve({\n ...paymentRequirements,\n extra: {\n ...paymentRequirements.extra,\n assetTransferMethod: \"permit2\",\n ...(supportedKind.extra?.facilitatorAddress\n ? { facilitatorAddress: getAddress(supportedKind.extra.facilitatorAddress as string) }\n : {}),\n },\n });\n }\n\n /**\n * Parses a money string or number into a decimal value.\n *\n * @param money - The money value to parse\n * @returns The parsed decimal amount\n */\n private parseMoneyToDecimal(money: string | number): number {\n if (typeof money === \"number\") {\n return money;\n }\n\n return parseMoneyString(money);\n }\n\n /**\n * Converts a numeric dollar amount to an AssetAmount using the default token for the network.\n *\n * @param amount - The dollar amount as a number\n * @param network - The target network\n * @returns The converted asset amount with token metadata\n */\n private defaultMoneyConversion(amount: number, network: Network): AssetAmount {\n const assetInfo = getDefaultAsset(network);\n const tokenAmount = convertToTokenAmount(numberToDecimalString(amount), assetInfo.decimals);\n\n return {\n amount: tokenAmount,\n asset: assetInfo.address,\n extra: {\n name: assetInfo.name,\n version: assetInfo.version,\n assetTransferMethod: \"permit2\",\n },\n };\n }\n}\n","import type { Network } from \"@x402/core/types\";\n\n/**\n * Base stablecoin asset configuration shared across all EVM payment schemes.\n * Contains the core fields needed to identify and convert tokens.\n */\nexport type DefaultAssetInfo = {\n /** Token contract address */\n address: string;\n /** EIP-712 domain name (must match the token's domain separator) */\n name: string;\n /** EIP-712 domain version (must match the token's domain separator) */\n version: string;\n /** Token decimal places (typically 6 for USDC) */\n decimals: number;\n};\n\n/**\n * Extended asset configuration for the exact scheme.\n * Includes transfer method hints that control client-side behaviour.\n */\nexport type ExactDefaultAssetInfo = DefaultAssetInfo & {\n /**\n * Transfer method override: `\"permit2\"` for tokens that don't support EIP-3009.\n * Omit for EIP-3009 tokens (default behaviour).\n */\n assetTransferMethod?: string;\n /**\n * Set to `true` for permit2 tokens that implement EIP-2612 `permit()`.\n * Controls whether name/version are included in `extra` so the client can\n * sign a gasless EIP-2612 permit for Permit2 approval.\n */\n supportsEip2612?: boolean;\n};\n\n/**\n * Default stablecoins indexed by CAIP-2 network identifier.\n *\n * Each network has the right to determine its own default stablecoin that can\n * be expressed as a USD string by calling servers. See DEFAULT_ASSETS.md at the\n * repository root for how to add new chains.\n */\nexport const DEFAULT_STABLECOINS: Record<string, ExactDefaultAssetInfo> = {\n \"eip155:8453\": {\n address: \"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913\",\n name: \"USD Coin\",\n version: \"2\",\n decimals: 6,\n }, // Base mainnet USDC\n \"eip155:84532\": {\n address: \"0x036CbD53842c5426634e7929541eC2318f3dCF7e\",\n name: \"USDC\",\n version: \"2\",\n decimals: 6,\n }, // Base Sepolia USDC\n \"eip155:4326\": {\n address: \"0xFAfDdbb3FC7688494971a79cc65DCa3EF82079E7\",\n name: \"MegaUSD\",\n version: \"1\",\n decimals: 18,\n assetTransferMethod: \"permit2\",\n supportsEip2612: true,\n }, // MegaETH mainnet MegaUSD (no EIP-3009, supports EIP-2612)\n \"eip155:143\": {\n address: \"0x754704Bc059F8C67012fEd69BC8A327a5aafb603\",\n name: \"USDC\",\n version: \"2\",\n decimals: 6,\n }, // Monad mainnet USDC\n \"eip155:988\": {\n address: \"0x779Ded0c9e1022225f8E0630b35a9b54bE713736\",\n name: \"USDT0\",\n version: \"1\",\n decimals: 6,\n }, // Stable mainnet USDT0\n \"eip155:2201\": {\n address: \"0x78Cf24370174180738C5B8E352B6D14c83a6c9A9\",\n name: \"USDT0\",\n version: \"1\",\n decimals: 6,\n }, // Stable testnet USDT0\n \"eip155:137\": {\n address: \"0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359\",\n name: \"USD Coin\",\n version: \"2\",\n decimals: 6,\n }, // Polygon mainnet USDC\n \"eip155:42161\": {\n address: \"0xaf88d065e77c8cC2239327C5EDb3A432268e5831\",\n name: \"USD Coin\",\n version: \"2\",\n decimals: 6,\n }, // Arbitrum One USDC\n \"eip155:421614\": {\n address: \"0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d\",\n name: \"USD Coin\",\n version: \"2\",\n decimals: 6,\n }, // Arbitrum Sepolia USDC\n \"eip155:31612\": {\n address: \"0xdD468A1DDc392dcdbEf6db6e34E89AA338F9F186\",\n name: \"Mezo USD\",\n version: \"1\",\n decimals: 18,\n assetTransferMethod: \"permit2\",\n supportsEip2612: true,\n }, // Mezo mainnet mUSD (no EIP-3009, supports EIP-2612)\n \"eip155:31611\": {\n address: \"0x118917a40FAF1CD7a13dB0Ef56C86De7973Ac503\",\n name: \"Mezo USD\",\n version: \"1\",\n decimals: 18,\n assetTransferMethod: \"permit2\",\n supportsEip2612: true,\n }, // Mezo Testnet mUSD (no EIP-3009, supports EIP-2612)\n \"eip155:723487\": {\n address: \"0x33ad9e4BD16B69B5BFdED37D8B5D9fF9aba014Fb\",\n name: \"Stable Coin\",\n version: \"1\",\n decimals: 6,\n assetTransferMethod: \"permit2\",\n supportsEip2612: true,\n }, // Radius Network SBC (no EIP-3009, supports EIP-2612)\n \"eip155:72344\": {\n address: \"0x33ad9e4BD16B69B5BFdED37D8B5D9fF9aba014Fb\",\n name: \"Stable Coin\",\n version: \"1\",\n decimals: 6,\n assetTransferMethod: \"permit2\",\n supportsEip2612: true,\n }, // Radius Testnet SBC (no EIP-3009, supports EIP-2612)\n \"eip155:36900\": {\n address: \"0x9cb8142aEBBcdc60AF7c97Af897A67A8f3CA71C2\",\n name: \"USDC.e\",\n version: \"2\",\n decimals: 6,\n }, // ADI Chain USDC.e (EIP-3009 supported)\n \"eip155:190415\": {\n address: \"0x401eCb1D350407f13ba348573E5630B83638E30D\",\n name: \"Bridged USDC\",\n version: \"2\",\n decimals: 6,\n }, // HPP mainnet USDC.e\n \"eip155:181228\": {\n address: \"0x401eCb1D350407f13ba348573E5630B83638E30D\",\n name: \"Bridged USDC\",\n version: \"2\",\n decimals: 6,\n }, // HPP Sepolia USDC.e\n \"eip155:50\": {\n address: \"0xfA2958CB79b0491CC627c1557F441eF849Ca8eb1\",\n name: \"USDC\",\n version: \"2\",\n decimals: 6,\n }, // XDC Network mainnet USDC (Bridged USDC Standard, EIP-3009 supported)\n \"eip155:51\": {\n address: \"0xb5AB69F7bBada22B28e79C8FFAECe55eF1c771D4\",\n name: \"USDC\",\n version: \"2\",\n decimals: 6,\n }, // XDC Apothem testnet USDC (Bridged USDC Standard, EIP-3009 supported)\n \"eip155:38833\": {\n address: \"0xA5b8BF902b2844dA17d4506cc827F7F1681735E7\",\n name: \"USDC\",\n version: \"1\",\n decimals: 6,\n assetTransferMethod: \"permit2\",\n }, // Igra mainnet USDC (no EIP-3009, no EIP-2612)\n \"eip155:14\": {\n address: \"0xe7cd86e13AC4309349F30B3435a9d337750fC82D\",\n name: \"USD\\u20AE0\",\n version: \"1\",\n decimals: 6,\n }, // Flare mainnet USD₮0 (EIP-3009 supported)\n \"eip155:42220\": {\n address: \"0xcebA9300f2b948710d2653dD7B07f33A8B32118C\",\n name: \"USDC\",\n version: \"2\",\n decimals: 6,\n }, // Celo mainnet USDC (EIP-3009 supported)\n \"eip155:11142220\": {\n address: \"0x01C5C0122039549AD1493B8220cABEdD739BC44E\",\n name: \"USDC\",\n version: \"2\",\n decimals: 6,\n }, // Celo Sepolia testnet USDC (EIP-3009 supported)\n};\n\n/**\n * Look up the default stablecoin for a network.\n *\n * @param network - CAIP-2 network identifier (e.g. \"eip155:8453\")\n * @returns The default asset info\n * @throws If no default asset is configured for the network\n */\nexport function getDefaultAsset(network: Network): ExactDefaultAssetInfo {\n const info = DEFAULT_STABLECOINS[network];\n if (!info) {\n throw new Error(`No default asset configured for network ${network}`);\n }\n return info;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACSA,mBAA8E;AAC9E,kBAA2B;;;ACgCpB,IAAM,sBAA6D;AAAA,EACxE,eAAe;AAAA,IACb,SAAS;AAAA,IACT,MAAM;AAAA,IACN,SAAS;AAAA,IACT,UAAU;AAAA,EACZ;AAAA;AAAA,EACA,gBAAgB;AAAA,IACd,SAAS;AAAA,IACT,MAAM;AAAA,IACN,SAAS;AAAA,IACT,UAAU;AAAA,EACZ;AAAA;AAAA,EACA,eAAe;AAAA,IACb,SAAS;AAAA,IACT,MAAM;AAAA,IACN,SAAS;AAAA,IACT,UAAU;AAAA,IACV,qBAAqB;AAAA,IACrB,iBAAiB;AAAA,EACnB;AAAA;AAAA,EACA,cAAc;AAAA,IACZ,SAAS;AAAA,IACT,MAAM;AAAA,IACN,SAAS;AAAA,IACT,UAAU;AAAA,EACZ;AAAA;AAAA,EACA,cAAc;AAAA,IACZ,SAAS;AAAA,IACT,MAAM;AAAA,IACN,SAAS;AAAA,IACT,UAAU;AAAA,EACZ;AAAA;AAAA,EACA,eAAe;AAAA,IACb,SAAS;AAAA,IACT,MAAM;AAAA,IACN,SAAS;AAAA,IACT,UAAU;AAAA,EACZ;AAAA;AAAA,EACA,cAAc;AAAA,IACZ,SAAS;AAAA,IACT,MAAM;AAAA,IACN,SAAS;AAAA,IACT,UAAU;AAAA,EACZ;AAAA;AAAA,EACA,gBAAgB;AAAA,IACd,SAAS;AAAA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,QACL,MAAM,UAAU;AAAA,QAChB,SAAS,UAAU;AAAA,QACnB,qBAAqB;AAAA,MACvB;AAAA,IACF;AAAA,EACF;AACF;","names":[]}

@@ -1,2 +0,2 @@

import { F as FileChannelStorageOptions } from '../../types-DIt9uAUy.mjs';
import { F as FileChannelStorageOptions } from '../../types-B4ib_1f_.mjs';
import { C as ClientChannelStorage, B as BatchSettlementClientContext } from '../../storage-BFpn16ZW.mjs';

@@ -3,0 +3,0 @@ import 'viem';

@@ -1,7 +0,7 @@

import { B as BatchSettlementClientDeps } from '../../scheme-Aweh1VGY.mjs';
export { b as BatchSettlementDepositPolicy, c as BatchSettlementDepositStrategy, d as BatchSettlementDepositStrategyContext, e as BatchSettlementDepositStrategyResult, a as BatchSettlementEvmScheme, f as BatchSettlementEvmSchemeOptions, R as RefundOptions, j as ResolvedClientOptions, k as buildChannelConfig, g as depositAmountForRequest, l as getChannel, m as hasChannel, i as isBatchSettlementEvmSchemeOptions, p as processPaymentResponse, n as processSettleResponse, o as readChannelBalanceAndTotalClaimed, q as recoverChannel, r as refundChannel, h as resolveClientOptions, u as updateChannelAfterRefund, v as validateDepositPolicy } from '../../scheme-Aweh1VGY.mjs';
import { B as BatchSettlementClientDeps } from '../../scheme-CFbBP1Js.mjs';
export { b as BatchSettlementDepositPolicy, c as BatchSettlementDepositStrategy, d as BatchSettlementDepositStrategyContext, e as BatchSettlementDepositStrategyResult, a as BatchSettlementEvmScheme, f as BatchSettlementEvmSchemeOptions, R as RefundOptions, j as ResolvedClientOptions, k as buildChannelConfig, g as depositAmountForRequest, l as getChannel, m as hasChannel, i as isBatchSettlementEvmSchemeOptions, p as processPaymentResponse, n as processSettleResponse, o as readChannelBalanceAndTotalClaimed, q as recoverChannel, r as refundChannel, h as resolveClientOptions, u as updateChannelAfterRefund, v as validateDepositPolicy } from '../../scheme-CFbBP1Js.mjs';
export { B as BatchSettlementClientContext, C as ClientChannelStorage, I as InMemoryClientChannelStorage } from '../../storage-BFpn16ZW.mjs';
import { PaymentRequirements, PaymentPayloadResult, SchemeClientHooks, PaymentRequired } from '@x402/core/types';
import { C as ClientEvmSigner } from '../../signer-B127taDR.mjs';
import { C as ChannelConfig, a as BatchSettlementVoucherFields, b as BatchSettlementChannelStateExtra, c as BatchSettlementVoucherStateExtra } from '../../types-DIt9uAUy.mjs';
import { C as ChannelConfig, b as BatchSettlementVoucherFields, c as BatchSettlementChannelStateExtra, d as BatchSettlementVoucherStateExtra } from '../../types-B4ib_1f_.mjs';
import { PaymentResponseContext } from '@x402/core/client';

@@ -8,0 +8,0 @@ import '../../rpc-DULZzRne.mjs';

import { SchemeNetworkFacilitator, PaymentPayload, PaymentRequirements, FacilitatorContext, VerifyResponse, SettleResponse } from '@x402/core/types';
import { F as FacilitatorEvmSigner } from '../../signer-B127taDR.mjs';
import { A as AuthorizerSigner } from '../../types-DIt9uAUy.mjs';
import { A as AuthorizerSigner } from '../../types-B4ib_1f_.mjs';
import 'viem';

@@ -5,0 +5,0 @@

@@ -1,3 +0,3 @@

import { F as FileChannelStorageOptions } from '../../types-DIt9uAUy.mjs';
import { C as ChannelStorage, a as Channel, b as ChannelUpdateResult } from '../../storage-BEzTEiUr.mjs';
import { F as FileChannelStorageOptions } from '../../types-B4ib_1f_.mjs';
import { C as ChannelStorage, a as Channel, b as ChannelUpdateResult } from '../../storage-BlE8v9vt.mjs';
import 'viem';

@@ -4,0 +4,0 @@

import { Network, SchemePaymentRequiredContext, SchemeNetworkServer, SchemeServerHooks, PaymentRequirements, DeepReadonly, PaymentPayload, MoneyParser, Price, AssetAmount, SupportedKind } from '@x402/core/types';
import { FacilitatorClient, SettleContext, SettleResultContext } from '@x402/core/server';
import { B as BatchSettlementVoucherClaim, A as AuthorizerSigner } from '../../types-DIt9uAUy.mjs';
import { a as Channel, C as ChannelStorage } from '../../storage-BEzTEiUr.mjs';
export { b as ChannelUpdateResult, I as InMemoryChannelStorage, P as PendingRequest } from '../../storage-BEzTEiUr.mjs';
import { B as BatchSettlementVoucherClaim, a as BatchSettlementAssetTransferMethod, A as AuthorizerSigner } from '../../types-B4ib_1f_.mjs';
import { a as Channel, C as ChannelStorage } from '../../storage-BlE8v9vt.mjs';
export { b as ChannelUpdateResult, I as InMemoryChannelStorage, P as PendingRequest } from '../../storage-BlE8v9vt.mjs';
import 'viem';

@@ -325,2 +325,13 @@

readonly scheme: "batch-settlement";
readonly defaultAssetTransferMethod: BatchSettlementAssetTransferMethod;
readonly paymentFlows: {
readonly eip3009: {
readonly supported: readonly ["authorization"];
readonly default: "authorization";
};
readonly permit2: {
readonly supported: readonly ["authorization"];
readonly default: "authorization";
};
};
readonly schemeHooks: SchemeServerHooks;

@@ -327,0 +338,0 @@ private readonly requestContexts;

@@ -30,3 +30,3 @@ import {

getDefaultAsset
} from "../../chunk-KTVL22S4.mjs";
} from "../../chunk-HR3TFOGA.mjs";
import {

@@ -1389,2 +1389,7 @@ isBatchSettlementDepositPayload,

this.scheme = BATCH_SETTLEMENT_SCHEME;
this.defaultAssetTransferMethod = "eip3009";
this.paymentFlows = {
eip3009: { supported: ["authorization"], default: "authorization" },
permit2: { supported: ["authorization"], default: "authorization" }
};
this.requestContexts = /* @__PURE__ */ new WeakMap();

@@ -1391,0 +1396,0 @@ this.moneyParsers = [];

@@ -1,3 +0,3 @@

import { C as ChannelStorage, a as Channel, b as ChannelUpdateResult } from '../../storage-BEzTEiUr.mjs';
import '../../types-DIt9uAUy.mjs';
import { C as ChannelStorage, a as Channel, b as ChannelUpdateResult } from '../../storage-BlE8v9vt.mjs';
import '../../types-B4ib_1f_.mjs';
import 'viem';

@@ -4,0 +4,0 @@

import { SchemeNetworkServer, MoneyParser, Network, Price, AssetAmount, PaymentRequirements } from '@x402/core/types';
import { A as AssetTransferMethod } from '../../types-BBC1mC8d.mjs';
import { x402ResourceServer } from '@x402/core/server';

@@ -9,2 +10,13 @@

readonly scheme = "exact";
readonly defaultAssetTransferMethod: AssetTransferMethod;
readonly paymentFlows: {
readonly eip3009: {
readonly supported: readonly ["authorization"];
readonly default: "authorization";
};
readonly permit2: {
readonly supported: readonly ["authorization"];
readonly default: "authorization";
};
};
private moneyParsers;

@@ -11,0 +23,0 @@ /**

import {
getDefaultAsset
} from "../../chunk-KTVL22S4.mjs";
} from "../../chunk-HR3TFOGA.mjs";

@@ -10,2 +10,7 @@ // src/exact/server/scheme.ts

this.scheme = "exact";
this.defaultAssetTransferMethod = "eip3009";
this.paymentFlows = {
eip3009: { supported: ["authorization"], default: "authorization" },
permit2: { supported: ["authorization"], default: "authorization" }
};
this.moneyParsers = [];

@@ -12,0 +17,0 @@ }

@@ -1,1 +0,1 @@

{"version":3,"sources":["../../../../src/exact/server/scheme.ts","../../../../src/exact/server/register.ts"],"sourcesContent":["import {\n AssetAmount,\n Network,\n PaymentRequirements,\n Price,\n SchemeNetworkServer,\n MoneyParser,\n} from \"@x402/core/types\";\nimport { convertToTokenAmount, numberToDecimalString, parseMoneyString } from \"@x402/core/utils\";\nimport { getDefaultAsset, type ExactDefaultAssetInfo } from \"../../shared/defaultAssets\";\n\n/**\n * EVM server implementation for the Exact payment scheme.\n */\nexport class ExactEvmScheme implements SchemeNetworkServer {\n readonly scheme = \"exact\";\n private moneyParsers: MoneyParser[] = [];\n\n /**\n * Register a custom money parser in the parser chain.\n * Multiple parsers can be registered - they will be tried in registration order.\n * Each parser receives a decimal amount (e.g., 1.50 for $1.50).\n * If a parser returns null, the next parser in the chain will be tried.\n * The default parser is always the final fallback.\n *\n * @param parser - Custom function to convert amount to AssetAmount (or null to skip)\n * @returns The server instance for chaining\n *\n * @example\n * evmServer.registerMoneyParser(async (amount, network) => {\n * // Custom conversion logic\n * if (amount > 100) {\n * // Use different token for large amounts\n * return { amount: (amount * 1e18).toString(), asset: \"0xCustomToken\" };\n * }\n * return null; // Use next parser\n * });\n */\n registerMoneyParser(parser: MoneyParser): ExactEvmScheme {\n this.moneyParsers.push(parser);\n return this;\n }\n\n /**\n * Returns the decimal precision of the default stablecoin for the given network.\n * Implements the optional AssetDecimalsProvider interface used by resolveSettlementOverrideAmount.\n *\n * @param _asset - The asset symbol (unused; defaults to the network's default stablecoin)\n * @param network - The network to look up the default asset for\n * @returns The number of decimal places for the asset\n */\n getAssetDecimals(_asset: string, network: Network): number {\n try {\n return getDefaultAsset(network).decimals;\n } catch {\n return 6;\n }\n }\n\n /**\n * Parses a price into an asset amount.\n * If price is already an AssetAmount, returns it directly.\n * If price is Money (string | number), parses to decimal and tries custom parsers.\n * Falls back to default conversion if all custom parsers return null.\n *\n * @param price - The price to parse\n * @param network - The network to use\n * @returns Promise that resolves to the parsed asset amount\n */\n async parsePrice(price: Price, network: Network): Promise<AssetAmount> {\n // If already an AssetAmount, return it directly\n if (typeof price === \"object\" && price !== null && \"amount\" in price) {\n if (!price.asset) {\n throw new Error(`Asset address must be specified for AssetAmount on network ${network}`);\n }\n return {\n amount: price.amount,\n asset: price.asset,\n extra: price.extra || {},\n };\n }\n\n // Parse Money to decimal number\n const amount = this.parseMoneyToDecimal(price);\n\n // Try each custom money parser in order\n for (const parser of this.moneyParsers) {\n const result = await parser(amount, network);\n if (result !== null) {\n return result;\n }\n }\n\n // All custom parsers returned null, use default conversion\n return this.defaultMoneyConversion(amount, network);\n }\n\n /**\n * Build payment requirements for this scheme/network combination\n *\n * @param paymentRequirements - The base payment requirements\n * @param supportedKind - The supported kind from facilitator (unused)\n * @param supportedKind.x402Version - The x402 version\n * @param supportedKind.scheme - The logical payment scheme\n * @param supportedKind.network - The network identifier in CAIP-2 format\n * @param supportedKind.extra - Optional extra metadata regarding scheme/network implementation details\n * @param extensionKeys - Extension keys supported by the facilitator (unused)\n * @returns Payment requirements ready to be sent to clients\n */\n enhancePaymentRequirements(\n paymentRequirements: PaymentRequirements,\n supportedKind: {\n x402Version: number;\n scheme: string;\n network: Network;\n extra?: Record<string, unknown>;\n },\n extensionKeys: string[],\n ): Promise<PaymentRequirements> {\n // Mark unused parameters to satisfy linter\n void supportedKind;\n void extensionKeys;\n return Promise.resolve(paymentRequirements);\n }\n\n /**\n * Parse Money (string | number) to a decimal number.\n * Handles formats like \"$1.50\", \"1.50\", 1.50, etc.\n *\n * @param money - The money value to parse\n * @returns Decimal number\n */\n private parseMoneyToDecimal(money: string | number): number {\n if (typeof money === \"number\") {\n return money;\n }\n\n return parseMoneyString(money);\n }\n\n /**\n * Converts a numeric dollar amount to an AssetAmount using the default token for the network.\n *\n * @param amount - The dollar amount as a number\n * @param network - The target network\n * @returns The converted asset amount with token metadata\n */\n private defaultMoneyConversion(amount: number, network: Network): AssetAmount {\n const assetInfo: ExactDefaultAssetInfo = getDefaultAsset(network);\n const tokenAmount = convertToTokenAmount(numberToDecimalString(amount), assetInfo.decimals);\n\n // EIP-3009 tokens always need name/version for their transferWithAuthorization domain.\n // Permit2 tokens only need them if the token supports EIP-2612 (for gasless permit signing).\n // Omitting name/version for permit2 tokens signals the client to skip EIP-2612 and use\n // ERC-20 approval gas sponsoring instead.\n const includeEip712Domain = !assetInfo.assetTransferMethod || assetInfo.supportsEip2612;\n\n return {\n amount: tokenAmount,\n asset: assetInfo.address,\n extra: {\n ...(includeEip712Domain && {\n name: assetInfo.name,\n version: assetInfo.version,\n }),\n ...(assetInfo.assetTransferMethod && {\n assetTransferMethod: assetInfo.assetTransferMethod,\n }),\n },\n };\n }\n}\n","import { x402ResourceServer } from \"@x402/core/server\";\nimport { Network } from \"@x402/core/types\";\nimport { ExactEvmScheme } from \"./scheme\";\n\n/**\n * Configuration options for registering EVM schemes to an x402ResourceServer\n */\nexport interface EvmResourceServerConfig {\n /**\n * Optional specific networks to register\n * If not provided, registers wildcard support (eip155:*)\n */\n networks?: Network[];\n}\n\n/**\n * Registers EVM exact payment schemes to an x402ResourceServer instance.\n *\n * This function registers:\n * - V2: eip155:* wildcard scheme with ExactEvmScheme (or specific networks if provided)\n *\n * @param server - The x402ResourceServer instance to register schemes to\n * @param config - Configuration for EVM resource server registration\n * @returns The server instance for chaining\n *\n * @example\n * ```typescript\n * import { registerExactEvmScheme } from \"@x402/evm/exact/server/register\";\n * import { x402ResourceServer } from \"@x402/core/server\";\n *\n * const server = new x402ResourceServer(facilitatorClient);\n * registerExactEvmScheme(server, {});\n * ```\n */\nexport function registerExactEvmScheme(\n server: x402ResourceServer,\n config: EvmResourceServerConfig = {},\n): x402ResourceServer {\n // Register V2 scheme\n if (config.networks && config.networks.length > 0) {\n // Register specific networks\n config.networks.forEach(network => {\n server.register(network, new ExactEvmScheme());\n });\n } else {\n // Register wildcard for all EVM chains\n server.register(\"eip155:*\", new ExactEvmScheme());\n }\n\n return server;\n}\n"],"mappings":";;;;;AAQA,SAAS,sBAAsB,uBAAuB,wBAAwB;AAMvE,IAAM,iBAAN,MAAoD;AAAA,EAApD;AACL,SAAS,SAAS;AAClB,SAAQ,eAA8B,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAsBvC,oBAAoB,QAAqC;AACvD,SAAK,aAAa,KAAK,MAAM;AAC7B,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,iBAAiB,QAAgB,SAA0B;AACzD,QAAI;AACF,aAAO,gBAAgB,OAAO,EAAE;AAAA,IAClC,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYA,MAAM,WAAW,OAAc,SAAwC;AAErE,QAAI,OAAO,UAAU,YAAY,UAAU,QAAQ,YAAY,OAAO;AACpE,UAAI,CAAC,MAAM,OAAO;AAChB,cAAM,IAAI,MAAM,8DAA8D,OAAO,EAAE;AAAA,MACzF;AACA,aAAO;AAAA,QACL,QAAQ,MAAM;AAAA,QACd,OAAO,MAAM;AAAA,QACb,OAAO,MAAM,SAAS,CAAC;AAAA,MACzB;AAAA,IACF;AAGA,UAAM,SAA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ACH,OAAO;AAEL,WAAO,SAAS,YAAY,IAAI,eAAe,CAAC;AAAA,EAClD;AAEA,SAAO;AACT;","names":[]}
{"version":3,"sources":["../../../../src/exact/server/scheme.ts","../../../../src/exact/server/register.ts"],"sourcesContent":["import {\n AssetAmount,\n Network,\n PaymentFlowConfig,\n PaymentRequirements,\n Price,\n SchemeNetworkServer,\n MoneyParser,\n} from \"@x402/core/types\";\nimport { convertToTokenAmount, numberToDecimalString, parseMoneyString } from \"@x402/core/utils\";\nimport { getDefaultAsset, type ExactDefaultAssetInfo } from \"../../shared/defaultAssets\";\nimport type { AssetTransferMethod } from \"../../types\";\n\n/**\n * EVM server implementation for the Exact payment scheme.\n */\nexport class ExactEvmScheme implements SchemeNetworkServer {\n readonly scheme = \"exact\";\n readonly defaultAssetTransferMethod: AssetTransferMethod = \"eip3009\";\n readonly paymentFlows = {\n eip3009: { supported: [\"authorization\"], default: \"authorization\" },\n permit2: { supported: [\"authorization\"], default: \"authorization\" },\n } as const satisfies Record<AssetTransferMethod, PaymentFlowConfig>;\n private moneyParsers: MoneyParser[] = [];\n\n /**\n * Register a custom money parser in the parser chain.\n * Multiple parsers can be registered - they will be tried in registration order.\n * Each parser receives a decimal amount (e.g., 1.50 for $1.50).\n * If a parser returns null, the next parser in the chain will be tried.\n * The default parser is always the final fallback.\n *\n * @param parser - Custom function to convert amount to AssetAmount (or null to skip)\n * @returns The server instance for chaining\n *\n * @example\n * evmServer.registerMoneyParser(async (amount, network) => {\n * // Custom conversion logic\n * if (amount > 100) {\n * // Use different token for large amounts\n * return { amount: (amount * 1e18).toString(), asset: \"0xCustomToken\" };\n * }\n * return null; // Use next parser\n * });\n */\n registerMoneyParser(parser: MoneyParser): ExactEvmScheme {\n this.moneyParsers.push(parser);\n return this;\n }\n\n /**\n * Returns the decimal precision of the default stablecoin for the given network.\n * Implements the optional AssetDecimalsProvider interface used by resolveSettlementOverrideAmount.\n *\n * @param _asset - The asset symbol (unused; defaults to the network's default stablecoin)\n * @param network - The network to look up the default asset for\n * @returns The number of decimal places for the asset\n */\n getAssetDecimals(_asset: string, network: Network): number {\n try {\n return getDefaultAsset(network).decimals;\n } catch {\n return 6;\n }\n }\n\n /**\n * Parses a price into an asset amount.\n * If price is already an AssetAmount, returns it directly.\n * If price is Money (string | number), parses to decimal and tries custom parsers.\n * Falls back to default conversion if all custom parsers return null.\n *\n * @param price - The price to parse\n * @param network - The network to use\n * @returns Promise that resolves to the parsed asset amount\n */\n async parsePrice(price: Price, network: Network): Promise<AssetAmount> {\n // If already an AssetAmount, return it directly\n if (typeof price === \"object\" && price !== null && \"amount\" in price) {\n if (!price.asset) {\n throw new Error(`Asset address must be specified for AssetAmount on network ${network}`);\n }\n return {\n amount: price.amount,\n asset: price.asset,\n extra: price.extra || {},\n };\n }\n\n // Parse Money to decimal number\n const amount = this.parseMoneyToDecimal(price);\n\n // Try each custom money parser in order\n for (const parser of this.moneyParsers) {\n const result = await parser(amount, network);\n if (result !== null) {\n return result;\n }\n }\n\n // All custom parsers returned null, use default conversion\n return this.defaultMoneyConversion(amount, network);\n }\n\n /**\n * Build payment requirements for this scheme/network combination\n *\n * @param paymentRequirements - The base payment requirements\n * @param supportedKind - The supported kind from facilitator (unused)\n * @param supportedKind.x402Version - The x402 version\n * @param supportedKind.scheme - The logical payment scheme\n * @param supportedKind.network - The network identifier in CAIP-2 format\n * @param supportedKind.extra - Optional extra metadata regarding scheme/network implementation details\n * @param extensionKeys - Extension keys supported by the facilitator (unused)\n * @returns Payment requirements ready to be sent to clients\n */\n enhancePaymentRequirements(\n paymentRequirements: PaymentRequirements,\n supportedKind: {\n x402Version: number;\n scheme: string;\n network: Network;\n extra?: Record<string, unknown>;\n },\n extensionKeys: string[],\n ): Promise<PaymentRequirements> {\n // Mark unused parameters to satisfy linter\n void supportedKind;\n void extensionKeys;\n return Promise.resolve(paymentRequirements);\n }\n\n /**\n * Parse Money (string | number) to a decimal number.\n * Handles formats like \"$1.50\", \"1.50\", 1.50, etc.\n *\n * @param money - The money value to parse\n * @returns Decimal number\n */\n private parseMoneyToDecimal(money: string | number): number {\n if (typeof money === \"number\") {\n return money;\n }\n\n return parseMoneyString(money);\n }\n\n /**\n * Converts a numeric dollar amount to an AssetAmount using the default token for the network.\n *\n * @param amount - The dollar amount as a number\n * @param network - The target network\n * @returns The converted asset amount with token metadata\n */\n private defaultMoneyConversion(amount: number, network: Network): AssetAmount {\n const assetInfo: ExactDefaultAssetInfo = getDefaultAsset(network);\n const tokenAmount = convertToTokenAmount(numberToDecimalString(amount), assetInfo.decimals);\n\n // EIP-3009 tokens always need name/version for their transferWithAuthorization domain.\n // Permit2 tokens only need them if the token supports EIP-2612 (for gasless permit signing).\n // Omitting name/version for permit2 tokens signals the client to skip EIP-2612 and use\n // ERC-20 approval gas sponsoring instead.\n const includeEip712Domain = !assetInfo.assetTransferMethod || assetInfo.supportsEip2612;\n\n return {\n amount: tokenAmount,\n asset: assetInfo.address,\n extra: {\n ...(includeEip712Domain && {\n name: assetInfo.name,\n version: assetInfo.version,\n }),\n ...(assetInfo.assetTransferMethod && {\n assetTransferMethod: assetInfo.assetTransferMethod,\n }),\n },\n };\n }\n}\n","import { x402ResourceServer } from \"@x402/core/server\";\nimport { Network } from \"@x402/core/types\";\nimport { ExactEvmScheme } from \"./scheme\";\n\n/**\n * Configuration options for registering EVM schemes to an x402ResourceServer\n */\nexport interface EvmResourceServerConfig {\n /**\n * Optional specific networks to register\n * If not provided, registers wildcard support (eip155:*)\n */\n networks?: Network[];\n}\n\n/**\n * Registers EVM exact payment schemes to an x402ResourceServer instance.\n *\n * This function registers:\n * - V2: eip155:* wildcard scheme with ExactEvmScheme (or specific networks if provided)\n *\n * @param server - The x402ResourceServer instance to register schemes to\n * @param config - Configuration for EVM resource server registration\n * @returns The server instance for chaining\n *\n * @example\n * ```typescript\n * import { registerExactEvmScheme } from \"@x402/evm/exact/server/register\";\n * import { x402ResourceServer } from \"@x402/core/server\";\n *\n * const server = new x402ResourceServer(facilitatorClient);\n * registerExactEvmScheme(server, {});\n * ```\n */\nexport function registerExactEvmScheme(\n server: x402ResourceServer,\n config: EvmResourceServerConfig = {},\n): x402ResourceServer {\n // Register V2 scheme\n if (config.networks && config.networks.length > 0) {\n // Register specific networks\n config.networks.forEach(network => {\n server.register(network, new ExactEvmScheme());\n });\n } else {\n // Register wildcard for all EVM chains\n server.register(\"eip155:*\", new ExactEvmScheme());\n }\n\n return server;\n}\n"],"mappings":";;;;;AASA,SAAS,sBAAsB,uBAAuB,wBAAwB;AAOvE,IAAM,iBAAN,MAAoD;AAAA,EAApD;AACL,SAAS,SAAS;AAClB,SAAS,6BAAkD;AAC3D,SAAS,eAAe;AAAA,MACtB,SAAS,EAAE,WAAW,CAAC,eAAe,GAAG,SAAS,gBAAgB;AAAA,MAClE,SAAS,EAAE,WAAW,CAAC,eAAe,GAAG,SAAS,gBAAgB;AAAA,IACpE;AACA,SAAQ,eAA8B,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAsBvC,oBAAoB,QAAqC;AACvD,SAAK,aAAa,KAAK,MAAM;AAC7B,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,iBAAiB,QAAgB,SAA0B;AACzD,QAAI;AACF,aAAO,gBAAgB,OAAO,EAAE;AAAA,IAClC,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYA,MAAM,WAAW,OAAc,SAAwC;AAErE,QAAI,OAAO,UAAU,YAAY,UAAU,QAAQ,YAAY,OAAO;AACpE,UAAI,CAAC,MAAM,OAAO;AAChB,cAAM,IAAI,MAAM,8DAA8D,OAAO,EAAE;AAAA,MACzF;AACA,aAAO;AAAA,QACL,QAAQ,MAAM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D,WAAO,SAAS,QAAQ,aAAW;AACjC,aAAO,SAAS,SAAS,IAAI,eAAe,CAAC;AAAA,IAC/C,CAAC;AAAA,EACH,OAAO;AAEL,WAAO,SAAS,YAAY,IAAI,eAAe,CAAC;AAAA,EAClD;AAEA,SAAO;AACT;","names":[]}

@@ -5,5 +5,7 @@ export { E as ExactEvmScheme } from './scheme-B1OAu4_v.mjs';

export { a as PERMIT2_ADDRESS, P as Permit2AllowanceParams, d as authorizationTypes, c as createPermit2ApprovalTx, f as eip3009ABI, e as erc20AllowanceAbi, g as getPermit2AllowanceReadParams, p as permit2WitnessTypes, u as uptoPermit2WitnessTypes, h as x402ExactPermit2ProxyABI, x as x402ExactPermit2ProxyAddress, i as x402UptoPermit2ProxyABI, b as x402UptoPermit2ProxyAddress } from './permit2-DhJRUcgY.mjs';
import { A as AssetTransferMethod } from './types-BBC1mC8d.mjs';
export { E as ExactEIP3009Payload, b as ExactEvmPayloadV1, c as ExactEvmPayloadV2, a as ExactPermit2Payload, d as Permit2Authorization, P as Permit2Witness, g as UptoPermit2Authorization, U as UptoPermit2Payload, f as UptoPermit2Witness, e as isEIP3009Payload, i as isPermit2Payload, h as isUptoPermit2Payload } from './types-BBC1mC8d.mjs';
export { UptoEvmScheme } from './upto/client/index.mjs';
export { a as BatchSettlementEvmScheme } from './scheme-Aweh1VGY.mjs';
export { A as AuthorizerSigner, i as BatchSettlementClaimPayload, e as BatchSettlementDepositPayload, j as BatchSettlementEnrichedRefundPayload, h as BatchSettlementErc3009Authorization, m as BatchSettlementFacilitatorSettlePayload, k as BatchSettlementPayload, n as BatchSettlementPaymentRequirementsExtra, o as BatchSettlementPaymentResponseExtra, g as BatchSettlementRefundPayload, l as BatchSettlementSettlePayload, B as BatchSettlementVoucherClaim, a as BatchSettlementVoucherFields, f as BatchSettlementVoucherPayload, C as ChannelConfig, d as ChannelState, s as isBatchSettlementClaimPayload, p as isBatchSettlementDepositPayload, u as isBatchSettlementEnrichedRefundPayload, r as isBatchSettlementRefundPayload, t as isBatchSettlementSettlePayload, q as isBatchSettlementVoucherPayload } from './types-DIt9uAUy.mjs';
export { a as BatchSettlementEvmScheme } from './scheme-CFbBP1Js.mjs';
export { A as AuthorizerSigner, j as BatchSettlementClaimPayload, f as BatchSettlementDepositPayload, k as BatchSettlementEnrichedRefundPayload, i as BatchSettlementErc3009Authorization, n as BatchSettlementFacilitatorSettlePayload, l as BatchSettlementPayload, o as BatchSettlementPaymentRequirementsExtra, p as BatchSettlementPaymentResponseExtra, h as BatchSettlementRefundPayload, m as BatchSettlementSettlePayload, B as BatchSettlementVoucherClaim, b as BatchSettlementVoucherFields, g as BatchSettlementVoucherPayload, C as ChannelConfig, e as ChannelState, t as isBatchSettlementClaimPayload, q as isBatchSettlementDepositPayload, v as isBatchSettlementEnrichedRefundPayload, s as isBatchSettlementRefundPayload, u as isBatchSettlementSettlePayload, r as isBatchSettlementVoucherPayload } from './types-B4ib_1f_.mjs';
import { Network, FacilitatorContext, PaymentPayload, PaymentRequirements, FacilitatorExtension } from '@x402/core/types';

@@ -15,108 +17,2 @@ import { Hex, TypedDataDomain } from 'viem';

/**
* Asset transfer methods for the exact EVM scheme.
* - eip3009: Uses transferWithAuthorization (USDC, etc.) - recommended for compatible tokens
* - permit2: Uses Permit2 + x402Permit2Proxy - universal fallback for any ERC-20
*/
type AssetTransferMethod = "eip3009" | "permit2";
/**
* EIP-3009 payload for tokens with native transferWithAuthorization support.
*/
type ExactEIP3009Payload = {
signature?: `0x${string}`;
authorization: {
from: `0x${string}`;
to: `0x${string}`;
value: string;
validAfter: string;
validBefore: string;
nonce: `0x${string}`;
};
};
/**
* Permit2 witness data structure.
* Matches the Witness struct in x402Permit2Proxy contract.
* Note: Upper time bound is enforced by Permit2's `deadline` field, not a witness field.
*/
type Permit2Witness = {
to: `0x${string}`;
validAfter: string;
};
/**
* Permit2 authorization parameters.
* Used to reconstruct the signed message for verification.
*/
type Permit2Authorization = {
permitted: {
token: `0x${string}`;
amount: string;
};
spender: `0x${string}`;
nonce: string;
deadline: string;
witness: Permit2Witness;
};
/**
* Permit2 payload for tokens using the Permit2 + x402Permit2Proxy flow.
*/
type ExactPermit2Payload = {
signature: `0x${string}`;
permit2Authorization: Permit2Authorization & {
from: `0x${string}`;
};
};
type ExactEvmPayloadV1 = ExactEIP3009Payload;
type ExactEvmPayloadV2 = ExactEIP3009Payload | ExactPermit2Payload;
/**
* Type guard to check if a payload is a Permit2 payload.
* Permit2 payloads have a `permit2Authorization` field.
*
* @param payload - The payload to check.
* @returns True if the payload is a Permit2 payload, false otherwise.
*/
declare function isPermit2Payload(payload: ExactEvmPayloadV2): payload is ExactPermit2Payload;
/**
* Type guard to check if a payload is an EIP-3009 payload.
* EIP-3009 payloads have an `authorization` field.
*
* @param payload - The payload to check.
* @returns True if the payload is an EIP-3009 payload, false otherwise.
*/
declare function isEIP3009Payload(payload: ExactEvmPayloadV2): payload is ExactEIP3009Payload;
/**
* Upto Permit2 witness — includes `facilitator` field absent from exact witness.
* Only the address matching `witness.facilitator` can call settle() on-chain.
*/
type UptoPermit2Witness = {
to: `0x${string}`;
facilitator: `0x${string}`;
validAfter: string;
};
type UptoPermit2Authorization = {
permitted: {
token: `0x${string}`;
amount: string;
};
spender: `0x${string}`;
nonce: string;
deadline: string;
witness: UptoPermit2Witness;
};
type UptoPermit2Payload = {
signature: `0x${string}`;
permit2Authorization: UptoPermit2Authorization & {
from: `0x${string}`;
};
};
/**
* Type guard to check if a payload is an upto Permit2 payload.
* Validates structural presence of all required fields: signature, permit2Authorization
* (with from, permitted, spender, nonce, deadline), and a witness containing facilitator.
*
* @param payload - The payload to check.
* @returns True if the payload is an upto Permit2 payload, false otherwise.
*/
declare function isUptoPermit2Payload(payload: Record<string, unknown>): payload is UptoPermit2Payload;
/** Scheme identifier for the batch-settlement payment scheme. */

@@ -452,2 +348,2 @@ declare const BATCH_SETTLEMENT_SCHEME: "batch-settlement";

export { AUTH_CAPTURE_ESCROW_ADDRESS, AUTH_CAPTURE_SCHEME, type AssetTransferMethod, type Eip3009Payload as AuthCaptureEip3009Payload, type AuthCaptureExtra, type AuthCapturePayload, type PaymentInfoStruct as AuthCapturePaymentInfo, type Permit2Payload as AuthCapturePermit2Payload, BATCH_SETTLEMENT_ADDRESS, BATCH_SETTLEMENT_DOMAIN, BATCH_SETTLEMENT_SCHEME, BUILDER_CODE_KEY, type BuilderCodeFacilitatorExtension, DEFAULT_STABLECOINS, type DataSuffixContext, type DefaultAssetInfo, EIP3009_TOKEN_COLLECTOR_ADDRESS, ERC3009_DEPOSIT_COLLECTOR_ADDRESS, type Erc6492Classification, type ExactDefaultAssetInfo, type ExactEIP3009Payload, type ExactEvmPayloadV1, type ExactEvmPayloadV2, type ExactPermit2Payload, FacilitatorEvmSigner, PERMIT2_TOKEN_COLLECTOR_ADDRESS, type Permit2Authorization, type Permit2Witness, type UptoPermit2Authorization, type UptoPermit2Payload, type UptoPermit2Witness, appendDataSuffix, claimBatchTypes, classifyErc6492Payer, getDefaultAsset, getERC7702DelegateAddress, isAuthCaptureExtra, isAuthCapturePayload, isEIP3009Payload, isERC7702Delegation, isPermit2Payload, isUptoPermit2Payload, refundTypes, resolveDataSuffix, verifyHashSignature, verifyHashSignatureWithCode, verifyTypedDataSignature, voucherTypes };
export { AUTH_CAPTURE_ESCROW_ADDRESS, AUTH_CAPTURE_SCHEME, AssetTransferMethod, type Eip3009Payload as AuthCaptureEip3009Payload, type AuthCaptureExtra, type AuthCapturePayload, type PaymentInfoStruct as AuthCapturePaymentInfo, type Permit2Payload as AuthCapturePermit2Payload, BATCH_SETTLEMENT_ADDRESS, BATCH_SETTLEMENT_DOMAIN, BATCH_SETTLEMENT_SCHEME, BUILDER_CODE_KEY, type BuilderCodeFacilitatorExtension, DEFAULT_STABLECOINS, type DataSuffixContext, type DefaultAssetInfo, EIP3009_TOKEN_COLLECTOR_ADDRESS, ERC3009_DEPOSIT_COLLECTOR_ADDRESS, type Erc6492Classification, type ExactDefaultAssetInfo, FacilitatorEvmSigner, PERMIT2_TOKEN_COLLECTOR_ADDRESS, appendDataSuffix, claimBatchTypes, classifyErc6492Payer, getDefaultAsset, getERC7702DelegateAddress, isAuthCaptureExtra, isAuthCapturePayload, isERC7702Delegation, refundTypes, resolveDataSuffix, verifyHashSignature, verifyHashSignatureWithCode, verifyTypedDataSignature, voucherTypes };

@@ -28,3 +28,3 @@ import {

getDefaultAsset
} from "./chunk-KTVL22S4.mjs";
} from "./chunk-HR3TFOGA.mjs";
import {

@@ -31,0 +31,0 @@ isEIP3009Payload,

import { SchemeNetworkServer, MoneyParser, Network, Price, AssetAmount, PaymentRequirements } from '@x402/core/types';
import { A as AssetTransferMethod } from '../../types-BBC1mC8d.mjs';

@@ -9,2 +10,9 @@ /**

readonly scheme = "upto";
readonly defaultAssetTransferMethod: AssetTransferMethod;
readonly paymentFlows: {
readonly permit2: {
readonly supported: readonly ["authorization"];
readonly default: "authorization";
};
};
private moneyParsers;

@@ -11,0 +19,0 @@ /**

import {
getDefaultAsset
} from "../../chunk-KTVL22S4.mjs";
} from "../../chunk-HR3TFOGA.mjs";

@@ -11,2 +11,6 @@ // src/upto/server/scheme.ts

this.scheme = "upto";
this.defaultAssetTransferMethod = "permit2";
this.paymentFlows = {
permit2: { supported: ["authorization"], default: "authorization" }
};
this.moneyParsers = [];

@@ -13,0 +17,0 @@ }

@@ -1,1 +0,1 @@

{"version":3,"sources":["../../../../src/upto/server/scheme.ts"],"sourcesContent":["import {\n AssetAmount,\n Network,\n PaymentRequirements,\n Price,\n SchemeNetworkServer,\n MoneyParser,\n} from \"@x402/core/types\";\nimport { convertToTokenAmount, numberToDecimalString, parseMoneyString } from \"@x402/core/utils\";\nimport { getAddress } from \"viem\";\nimport { getDefaultAsset } from \"../../shared/defaultAssets\";\n\n/**\n * EVM server implementation for the Upto payment scheme.\n * Handles price parsing, payment requirements enhancement, and default asset resolution.\n */\nexport class UptoEvmScheme implements SchemeNetworkServer {\n readonly scheme = \"upto\";\n private moneyParsers: MoneyParser[] = [];\n\n /**\n * Registers a custom money parser for converting prices to asset amounts.\n *\n * @param parser - The money parser function to register\n * @returns This instance for chaining\n */\n registerMoneyParser(parser: MoneyParser): UptoEvmScheme {\n this.moneyParsers.push(parser);\n return this;\n }\n\n /**\n * Returns the decimal precision of the default stablecoin for the given network.\n * Implements the optional AssetDecimalsProvider interface used by resolveSettlementOverrideAmount.\n *\n * @param _asset - The asset symbol (unused; defaults to the network's default stablecoin)\n * @param network - The network to look up the default asset for\n * @returns The number of decimal places for the asset\n */\n getAssetDecimals(_asset: string, network: Network): number {\n try {\n return getDefaultAsset(network).decimals;\n } catch {\n return 6;\n }\n }\n\n /**\n * Parses a price into an asset amount for the given network.\n *\n * @param price - The price to parse (string, number, or AssetAmount)\n * @param network - The target network\n * @returns Promise resolving to an asset amount\n */\n async parsePrice(price: Price, network: Network): Promise<AssetAmount> {\n if (typeof price === \"object\" && price !== null && \"amount\" in price) {\n if (!price.asset) {\n throw new Error(`Asset address must be specified for AssetAmount on network ${network}`);\n }\n return {\n amount: price.amount,\n asset: price.asset,\n extra: price.extra || {},\n };\n }\n\n const amount = this.parseMoneyToDecimal(price);\n\n for (const parser of this.moneyParsers) {\n const result = await parser(amount, network);\n if (result !== null) {\n return result;\n }\n }\n\n return this.defaultMoneyConversion(amount, network);\n }\n\n /**\n * Enhances payment requirements with upto-specific metadata.\n *\n * @param paymentRequirements - The base payment requirements\n * @param supportedKind - The supported scheme/network kind\n * @param supportedKind.x402Version - The x402 protocol version\n * @param supportedKind.scheme - The payment scheme name\n * @param supportedKind.network - The target network\n * @param supportedKind.extra - Optional extra metadata\n * @param extensionKeys - Extension keys to include\n * @returns Promise resolving to enhanced payment requirements\n */\n enhancePaymentRequirements(\n paymentRequirements: PaymentRequirements,\n supportedKind: {\n x402Version: number;\n scheme: string;\n network: Network;\n extra?: Record<string, unknown>;\n },\n extensionKeys: string[],\n ): Promise<PaymentRequirements> {\n void extensionKeys;\n return Promise.resolve({\n ...paymentRequirements,\n extra: {\n ...paymentRequirements.extra,\n assetTransferMethod: \"permit2\",\n ...(supportedKind.extra?.facilitatorAddress\n ? { facilitatorAddress: getAddress(supportedKind.extra.facilitatorAddress as string) }\n : {}),\n },\n });\n }\n\n /**\n * Parses a money string or number into a decimal value.\n *\n * @param money - The money value to parse\n * @returns The parsed decimal amount\n */\n private parseMoneyToDecimal(money: string | number): number {\n if (typeof money === \"number\") {\n return money;\n }\n\n return parseMoneyString(money);\n }\n\n /**\n * Converts a numeric dollar amount to an AssetAmount using the default token for the network.\n *\n * @param amount - The dollar amount as a number\n * @param network - The target network\n * @returns The converted asset amount with token metadata\n */\n private defaultMoneyConversion(amount: number, network: Network): AssetAmount {\n const assetInfo = getDefaultAsset(network);\n const tokenAmount = convertToTokenAmount(numberToDecimalString(amount), assetInfo.decimals);\n\n return {\n amount: tokenAmount,\n asset: assetInfo.address,\n extra: {\n name: assetInfo.name,\n version: assetInfo.version,\n assetTransferMethod: \"permit2\",\n },\n };\n }\n}\n"],"mappings":";;;;;AAQA,SAAS,sBAAsB,uBAAuB,wBAAwB;AAC9E,SAAS,kBAAkB;AAOpB,IAAM,gBAAN,MAAmD;AAAA,EAAnD;AACL,SAAS,SAAS;AAClB,SAAQ,eAA8B,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQvC,oBAAoB,QAAoC;AACtD,SAAK,aAAa,KAAK,MAAM;AAC7B,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,iBAAiB,QAAgB,SAA0B;AACzD,QAAI;AACF,aAAO,gBAAgB,OAAO,EAAE;AAAA,IAClC,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAM,WAAW,OAAc,SAAwC;AACrE,QAAI,OAAO,UAAU,YAAY,UAAU,QAAQ,YAAY,OAAO;AACpE,UAAI,CAAC,MAAM,OAAO;AAChB,c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B;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
{"version":3,"sources":["../../../../src/upto/server/scheme.ts"],"sourcesContent":["import {\n AssetAmount,\n Network,\n PaymentFlowConfig,\n PaymentRequirements,\n Price,\n SchemeNetworkServer,\n MoneyParser,\n} from \"@x402/core/types\";\nimport { convertToTokenAmount, numberToDecimalString, parseMoneyString } from \"@x402/core/utils\";\nimport { getAddress } from \"viem\";\nimport { getDefaultAsset } from \"../../shared/defaultAssets\";\nimport type { AssetTransferMethod } from \"../../types\";\n\n/**\n * EVM server implementation for the Upto payment scheme.\n * Handles price parsing, payment requirements enhancement, and default asset resolution.\n */\nexport class UptoEvmScheme implements SchemeNetworkServer {\n readonly scheme = \"upto\";\n readonly defaultAssetTransferMethod: AssetTransferMethod = \"permit2\";\n readonly paymentFlows = {\n permit2: { supported: [\"authorization\"], default: \"authorization\" },\n } as const satisfies Record<\"permit2\", PaymentFlowConfig>;\n private moneyParsers: MoneyParser[] = [];\n\n /**\n * Registers a custom money parser for converting prices to asset amounts.\n *\n * @param parser - The money parser function to register\n * @returns This instance for chaining\n */\n registerMoneyParser(parser: MoneyParser): UptoEvmScheme {\n this.moneyParsers.push(parser);\n return this;\n }\n\n /**\n * Returns the decimal precision of the default stablecoin for the given network.\n * Implements the optional AssetDecimalsProvider interface used by resolveSettlementOverrideAmount.\n *\n * @param _asset - The asset symbol (unused; defaults to the network's default stablecoin)\n * @param network - The network to look up the default asset for\n * @returns The number of decimal places for the asset\n */\n getAssetDecimals(_asset: string, network: Network): number {\n try {\n return getDefaultAsset(network).decimals;\n } catch {\n return 6;\n }\n }\n\n /**\n * Parses a price into an asset amount for the given network.\n *\n * @param price - The price to parse (string, number, or AssetAmount)\n * @param network - The target network\n * @returns Promise resolving to an asset amount\n */\n async parsePrice(price: Price, network: Network): Promise<AssetAmount> {\n if (typeof price === \"object\" && price !== null && \"amount\" in price) {\n if (!price.asset) {\n throw new Error(`Asset address must be specified for AssetAmount on network ${network}`);\n }\n return {\n amount: price.amount,\n asset: price.asset,\n extra: price.extra || {},\n };\n }\n\n const amount = this.parseMoneyToDecimal(price);\n\n for (const parser of this.moneyParsers) {\n const result = await parser(amount, network);\n if (result !== null) {\n return result;\n }\n }\n\n return this.defaultMoneyConversion(amount, network);\n }\n\n /**\n * Enhances payment requirements with upto-specific metadata.\n *\n * @param paymentRequirements - The base payment requirements\n * @param supportedKind - The supported scheme/network kind\n * @param supportedKind.x402Version - The x402 protocol version\n * @param supportedKind.scheme - The payment scheme name\n * @param supportedKind.network - The target network\n * @param supportedKind.extra - Optional extra metadata\n * @param extensionKeys - Extension keys to include\n * @returns Promise resolving to enhanced payment requirements\n */\n enhancePaymentRequirements(\n paymentRequirements: PaymentRequirements,\n supportedKind: {\n x402Version: number;\n scheme: string;\n network: Network;\n extra?: Record<string, unknown>;\n },\n extensionKeys: string[],\n ): Promise<PaymentRequirements> {\n void extensionKeys;\n return Promise.resolve({\n ...paymentRequirements,\n extra: {\n ...paymentRequirements.extra,\n assetTransferMethod: \"permit2\",\n ...(supportedKind.extra?.facilitatorAddress\n ? { facilitatorAddress: getAddress(supportedKind.extra.facilitatorAddress as string) }\n : {}),\n },\n });\n }\n\n /**\n * Parses a money string or number into a decimal value.\n *\n * @param money - The money value to parse\n * @returns The parsed decimal amount\n */\n private parseMoneyToDecimal(money: string | number): number {\n if (typeof money === \"number\") {\n return money;\n }\n\n return parseMoneyString(money);\n }\n\n /**\n * Converts a numeric dollar amount to an AssetAmount using the default token for the network.\n *\n * @param amount - The dollar amount as a number\n * @param network - The target network\n * @returns The converted asset amount with token metadata\n */\n private defaultMoneyConversion(amount: number, network: Network): AssetAmount {\n const assetInfo = getDefaultAsset(network);\n const tokenAmount = convertToTokenAmount(numberToDecimalString(amount), assetInfo.decimals);\n\n return {\n amount: tokenAmount,\n asset: assetInfo.address,\n extra: {\n name: assetInfo.name,\n version: assetInfo.version,\n assetTransferMethod: \"permit2\",\n },\n };\n }\n}\n"],"mappings":";;;;;AASA,SAAS,sBAA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AO,QAAQ,QAAQ;AAAA,MACrB,GAAG;AAAA,MACH,OAAO;AAAA,QACL,GAAG,oBAAoB;AAAA,QACvB,qBAAqB;AAAA,QACrB,GAAI,cAAc,OAAO,qBACrB,EAAE,oBAAoB,WAAW,cAAc,MAAM,kBAA4B,EAAE,IACnF,CAAC;AAAA,MACP;AAAA,IACF,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQQ,oBAAoB,OAAgC;AAC1D,QAAI,OAAO,UAAU,UAAU;AAC7B,aAAO;AAAA,IACT;AAEA,WAAO,iBAAiB,KAAK;AAAA,EAC/B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASQ,uBAAuB,QAAgB,SAA+B;AAC5E,UAAM,YAAY,gBAAgB,OAAO;AACzC,UAAM,cAAc,qBAAqB,sBAAsB,MAAM,GAAG,UAAU,QAAQ;AAE1F,WAAO;AAAA,MACL,QAAQ;AAAA,MACR,OAAO,UAAU;AAAA,MACjB,OAAO;AAAA,QACL,MAAM,UAAU;AAAA,QAChB,SAAS,UAAU;AAAA,QACnB,qBAAqB;AAAA,MACvB;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
{
"name": "@x402/evm",
"version": "2.21.0",
"version": "2.22.0",
"main": "./dist/cjs/index.js",

@@ -38,3 +38,3 @@ "module": "./dist/esm/index.js",

"zod": "^3.24.2",
"@x402/core": "~2.21.0"
"@x402/core": "~2.22.0"
},

@@ -41,0 +41,0 @@ "exports": {

import { PaymentRequirements, SettleResponse, SchemeNetworkClient, SchemeClientHooks, PaymentPayloadContext, PaymentPayloadResult, PaymentRequired } from '@x402/core/types';
import { C as ClientEvmSigner } from './signer-B127taDR.js';
import { C as ChannelConfig } from './types-DIt9uAUy.js';
import { c as EvmSchemeOptions } from './rpc-DULZzRne.js';
import { B as BatchSettlementClientContext, C as ClientChannelStorage } from './storage-BFpn16ZW.js';
/**
* Caller-tunable policy controlling how the client sizes channel deposits.
*/
interface BatchSettlementDepositPolicy {
depositMultiplier?: number;
}
/**
* Return shape for custom deposit sizing.
*/
type BatchSettlementDepositStrategyResult = string | bigint | false | undefined;
/**
* Information supplied before the client signs a deposit authorization.
*/
interface BatchSettlementDepositStrategyContext {
paymentRequirements: PaymentRequirements;
channelConfig: ChannelConfig;
channelId: `0x${string}`;
clientContext: BatchSettlementClientContext;
requestAmount: string;
maxClaimableAmount: string;
currentBalance: string;
minimumDepositAmount: string;
depositAmount: string;
}
/**
* Custom deposit sizing callback for initial deposits and top-ups.
*/
type BatchSettlementDepositStrategy = (context: BatchSettlementDepositStrategyContext) => BatchSettlementDepositStrategyResult | Promise<BatchSettlementDepositStrategyResult>;
/**
* Full options object accepted by `BatchSettlementEvmScheme`. Either this or a
* bare {@link BatchSettlementDepositPolicy} can be passed as the second
* constructor argument.
*/
interface BatchSettlementEvmSchemeOptions {
depositPolicy?: BatchSettlementDepositPolicy;
/** Optional callback for app-specific deposit sizing or skipping. */
depositStrategy?: BatchSettlementDepositStrategy;
storage?: ClientChannelStorage;
salt?: `0x${string}`;
payerAuthorizer?: `0x${string}`;
rpcUrl?: string;
/** When set, EIP-712 vouchers are signed with this key; deposits still use the main `signer`. */
voucherSigner?: ClientEvmSigner;
}
/**
* Resolved options after merging defaults — used internally by the scheme,
* recovery, and refund modules.
*/
interface ResolvedClientOptions {
depositPolicy?: BatchSettlementDepositPolicy;
depositStrategy?: BatchSettlementDepositStrategy;
storage: ClientChannelStorage;
salt: `0x${string}`;
payerAuthorizer?: `0x${string}`;
voucherSigner?: ClientEvmSigner;
extensionRpcOptions?: EvmSchemeOptions;
}
/**
* Discriminates a full options object from a bare deposit-policy object.
*
* @param o - Constructor argument that may be options, deposit policy only, or undefined.
* @returns `true` when `o` is a {@link BatchSettlementEvmSchemeOptions} object.
*/
declare function isBatchSettlementEvmSchemeOptions(o: BatchSettlementEvmSchemeOptions | BatchSettlementDepositPolicy | undefined): o is BatchSettlementEvmSchemeOptions;
/**
* Normalises the constructor's second argument into a uniform options shape.
*
* @param second - Optional second constructor argument (options or deposit policy).
* @returns Resolved storage, salt, deposit policy, and optional payer authorizer.
*/
declare function resolveClientOptions(second?: BatchSettlementEvmSchemeOptions | BatchSettlementDepositPolicy): ResolvedClientOptions;
/**
* Validates a {@link BatchSettlementDepositPolicy}, throwing on invalid fields.
*
* @param policy - The policy to validate (no-op when undefined).
*/
declare function validateDepositPolicy(policy: BatchSettlementDepositPolicy | undefined): void;
/**
* Computes the deposit amount based on the deposit multiplier.
*
* @param policy - Deposit policy controlling multiplier (may be undefined).
* @param requestAmount - Amount requested for this operation, in token base units.
* @returns Deposit amount string in token base units.
*/
declare function depositAmountForRequest(policy: BatchSettlementDepositPolicy | undefined, requestAmount: bigint): string;
/**
* Runtime dependency bag shared by every storage-bound client helper (channel,
* recovery, refund) and the {@link BatchSettlementEvmScheme} class.
*/
interface BatchSettlementClientDeps {
signer: ClientEvmSigner;
storage: ClientChannelStorage;
salt: `0x${string}`;
payerAuthorizer?: `0x${string}`;
voucherSigner?: ClientEvmSigner;
}
/**
* Constructs the immutable {@link ChannelConfig} from payment requirements and
* a client deps bag (signer, salt, optional payerAuthorizer / voucherSigner).
*
* @param deps - Client identity inputs.
* @param paymentRequirements - Server payment requirements providing receiver, asset, and extra fields.
* @returns The ChannelConfig that uniquely identifies this payment channel.
*/
declare function buildChannelConfig(deps: BatchSettlementClientDeps, paymentRequirements: PaymentRequirements): ChannelConfig;
/**
* Updates local channel state from a parsed `SettleResponse`.
*
* @param storage - Client channel storage.
* @param settle - The parsed settle response.
*/
declare function processSettleResponse(storage: ClientChannelStorage, settle: SettleResponse): Promise<void>;
/**
* Reconciles local channel state with the outcome of a cooperative refund.
*
* Deletes the channel record when the post-refund balance is zero (full refund),
* otherwise updates local state from the server snapshot.
*
* @param storage - Client channel storage.
* @param channelKey - Lowercased channel id used as the storage key.
* @param settleExtra - The `extra` block from the refund settle response.
*/
declare function updateChannelAfterRefund(storage: ClientChannelStorage, channelKey: string, settleExtra: Record<string, unknown>): Promise<void>;
/**
* Processes the `PAYMENT-RESPONSE` header after a successful request.
*
* Decodes the header into a `SettleResponse` and delegates to
* {@link processSettleResponse}.
*
* @param storage - Client channel storage.
* @param getHeader - Function to retrieve a response header by name.
*/
declare function processPaymentResponse(storage: ClientChannelStorage, getHeader: (name: string) => string | null | undefined): Promise<void>;
/**
* Recovers a channel record from onchain state (useful after a cold start or
* channel record loss).
*
* @param deps - Signer + storage + identity inputs.
* @param paymentRequirements - Server payment requirements used to derive the ChannelConfig.
* @returns The recovered client context.
*/
declare function recoverChannel(deps: BatchSettlementClientDeps, paymentRequirements: PaymentRequirements): Promise<BatchSettlementClientContext>;
/**
* Reads `channels(channelId)` returning `[balance, totalClaimed]`.
*
* @param signer - Signer providing `readContract`.
* @param channelId - The `bytes32` channel id to query.
* @returns Tuple of `[balance, totalClaimed]` as bigints.
*/
declare function readChannelBalanceAndTotalClaimed(signer: ClientEvmSigner, channelId: `0x${string}`): Promise<[bigint, bigint]>;
/**
* Returns whether a local channel record exists for the given channel.
*
* @param storage - Client channel storage.
* @param channelId - The channel identifier to check.
* @returns `true` when a channel record is stored.
*/
declare function hasChannel(storage: ClientChannelStorage, channelId: string): Promise<boolean>;
/**
* Returns the local channel context for a channel, if present.
*
* @param storage - Client channel storage.
* @param channelId - The channel identifier.
* @returns Stored context or `undefined`.
*/
declare function getChannel(storage: ClientChannelStorage, channelId: string): Promise<BatchSettlementClientContext | undefined>;
/**
* Caller-facing options for {@link refundChannel}.
*/
interface RefundOptions {
/** Token base units to refund; omit for a full refund (drains remaining balance). */
amount?: string;
/** Custom fetch implementation (defaults to `globalThis.fetch`). */
fetch?: typeof fetch;
}
/**
* Sends a cooperative refund request to the channel that backs `url`.
*
* Flow:
* 1. Probe the URL with `GET` (no payment) to obtain the route's payment requirements.
* 2. Build the `ChannelConfig` and resolve the local session (or recover it).
* 3. Sign a zero-charge refund voucher (`maxClaimableAmount = chargedCumulativeAmount`).
* 4. Send the voucher via `PAYMENT-SIGNATURE`. On a corrective 402, run the
* standard recovery path and retry once.
* 5. Return the parsed `SettleResponse` from the server.
*
* @param ctx - Identity inputs (storage, signers, salt, payerAuthorizer).
* @param url - Any protected route on the channel to refund (the resource handler is bypassed).
* @param options - Optional `amount` (partial refund) and `fetch` override.
* @returns The settle response describing the refund outcome.
* @throws When the probe fails, the receiver lacks an authorizer, or recovery fails.
*/
declare function refundChannel(ctx: BatchSettlementClientDeps, url: string, options?: RefundOptions): Promise<SettleResponse>;
/**
* Client-side implementation of the `batch-settlement` scheme for EVM networks.
*
* Builds payment payloads (deposit + voucher or voucher-only), processes server
* responses to update local session state via {@link processSettleResponse},
* handles corrective 402 resynchronisation via
* {@link processCorrectivePaymentRequired}, and supports on-demand cooperative
* refund requests via {@link refundChannel}.
*/
declare class BatchSettlementEvmScheme implements SchemeNetworkClient {
private readonly signer;
readonly scheme: "batch-settlement";
readonly schemeHooks: SchemeClientHooks;
private readonly storage;
private readonly depositPolicy;
private readonly depositStrategy;
private readonly salt;
private readonly payerAuthorizer;
private readonly voucherSigner;
private readonly extensionRpcOptions;
/**
* Constructs a batched client scheme.
*
* @param signer - Client EVM wallet used for signing vouchers and ERC-3009 authorizations.
* @param optionsOrPolicy - Either a full options object or a bare deposit-policy.
*/
constructor(signer: ClientEvmSigner, optionsOrPolicy?: BatchSettlementEvmSchemeOptions | BatchSettlementDepositPolicy);
/**
* Creates the payment payload for a batched request.
*
* If the channel has no onchain deposit (or needs a top-up), builds an
* ERC-3009 deposit payload bundled with a voucher. Otherwise, signs and
* returns a voucher-only payload.
*
* @param x402Version - Protocol version for the payload envelope.
* @param paymentRequirements - Server payment requirements (scheme, network, asset, amount).
* @param context - Optional payment payload context with extension hints.
* @returns A {@link PaymentPayloadResult} ready to be sent as the `X-PAYMENT` header.
*/
createPaymentPayload(x402Version: number, paymentRequirements: PaymentRequirements, context?: PaymentPayloadContext): Promise<PaymentPayloadResult>;
/**
* Sends a cooperative refund request.
*
* @param url - The route URL backing the channel to refund.
* @param options - Optional `amount` (partial refund) and `fetch` override.
* @returns The settle response describing the refund outcome.
*/
refund(url: string, options?: RefundOptions): Promise<SettleResponse>;
/**
* Updates local channel state from a settle response.
*
* @param settle - The parsed settle response from the server.
* @returns Resolves when local channel state has been updated.
*/
processSettleResponse(settle: SettleResponse): Promise<void>;
/**
* Resyncs local channel state from a corrective 402 response.
*
* @param paymentRequired - The decoded 402 response body.
* @returns `true` if local state was successfully resynced and a retry is warranted.
*/
processCorrectivePaymentRequired(paymentRequired: PaymentRequired): Promise<boolean>;
/**
* Builds the immutable {@link ChannelConfig} for a given set of payment
* requirements, using the scheme's own signer and salt.
*
* @param paymentRequirements - Server payment requirements for the channel.
* @returns The channel config that uniquely identifies the payment channel.
*/
buildChannelConfig(paymentRequirements: PaymentRequirements): ChannelConfig;
/**
* Resolves the deposit amount after applying the optional custom strategy.
*
* @param context - Deposit attempt context exposed to the strategy.
* @returns The deposit amount to sign, or `false` to skip this deposit attempt.
*/
private resolveDepositAmount;
/**
* Normalizes and validates a strategy-provided base-unit deposit amount.
*
* @param value - Strategy-provided string or bigint amount.
* @returns Normalized decimal string.
*/
private normalizeStrategyDepositAmount;
/**
* Signs a voucher-only payment payload for the current channel.
*
* @param x402Version - Protocol version for the payload envelope.
* @param channelId - Channel identifier for the voucher.
* @param maxClaimableAmount - Cumulative ceiling for the voucher.
* @param network - CAIP-2 network identifier.
* @param config - Immutable channel configuration.
* @returns Voucher-only payment payload.
*/
private createVoucherPayload;
/**
* Bundles the class state into the {@link BatchSettlementClientDeps} shape
* consumed by the `channel`, `recovery`, and `refund` modules.
*
* @returns Client deps wrapping the scheme's own signer and storage.
*/
private deps;
}
export { type BatchSettlementClientDeps as B, type RefundOptions as R, BatchSettlementEvmScheme as a, type BatchSettlementDepositPolicy as b, type BatchSettlementDepositStrategy as c, type BatchSettlementDepositStrategyContext as d, type BatchSettlementDepositStrategyResult as e, type BatchSettlementEvmSchemeOptions as f, depositAmountForRequest as g, resolveClientOptions as h, isBatchSettlementEvmSchemeOptions as i, type ResolvedClientOptions as j, buildChannelConfig as k, getChannel as l, hasChannel as m, processSettleResponse as n, readChannelBalanceAndTotalClaimed as o, processPaymentResponse as p, recoverChannel as q, refundChannel as r, updateChannelAfterRefund as u, validateDepositPolicy as v };
import { C as ChannelConfig } from './types-DIt9uAUy.js';
interface Channel {
channelId: string;
channelConfig: ChannelConfig;
chargedCumulativeAmount: string;
signedMaxClaimable: string;
signature: string;
balance: string;
totalClaimed: string;
withdrawRequestedAt: number;
refundNonce: number;
onchainSyncedAt?: number;
lastRequestTimestamp: number;
pendingRequest?: PendingRequest;
}
interface PendingRequest {
pendingId: string;
signedMaxClaimable: string;
expiresAt: number;
}
interface ChannelUpdateResult {
channel: Channel | undefined;
status: "updated" | "unchanged" | "deleted";
}
interface ChannelStorage {
get(channelId: string): Promise<Channel | undefined>;
list(): Promise<Channel[]>;
/**
* Atomically inspects and mutates a channel record.
*
* Implementations must guarantee that no concurrent mutation can interleave between
* reading `current` and writing the callback result for all application instances that
* share the backend. The in-memory backend only provides this guarantee inside one JS
* runtime; production multi-instance deployments need storage with backend-level atomic
* conditional mutation, such as Redis/Valkey Lua scripts, SQL transactions, or Durable Objects.
*
* @param channelId - The channel identifier.
* @param update - Mutation callback. Return `undefined` to delete, or `current` to leave unchanged.
* @returns The final stored channel and whether storage updated, stayed unchanged, or deleted.
*/
updateChannel(channelId: string, update: (current: Channel | undefined) => Channel | undefined): Promise<ChannelUpdateResult>;
}
/**
* In-memory {@link ChannelStorage} backed by a Map keyed by `channelId`.
*/
declare class InMemoryChannelStorage implements ChannelStorage {
private readonly channels;
private readonly channelLocks;
/**
* Returns the channel record for a channel, if present.
*
* @param channelId - The channel identifier.
* @returns The channel record or undefined when not found.
*/
get(channelId: string): Promise<Channel | undefined>;
/**
* Lists all stored channel records.
*
* @returns All channel records in storage.
*/
list(): Promise<Channel[]>;
/**
* Atomically inspects and mutates a channel record while holding a per-channel lock.
*
* @param channelId - The channel identifier.
* @param update - Mutation callback. Return `undefined` to delete, or `current` to leave unchanged.
* @returns The final stored channel and whether storage updated, stayed unchanged, or deleted.
*/
updateChannel(channelId: string, update: (current: Channel | undefined) => Channel | undefined): Promise<ChannelUpdateResult>;
/**
* Runs `fn` after any prior locked work for the same channel key has finished.
*
* @param key - Lowercased channel id used as the lock key.
* @param fn - Async work to run while holding the logical per-channel lock.
* @returns The resolved result of `fn`.
*/
private withChannelLock;
}
export { type ChannelStorage as C, InMemoryChannelStorage as I, type PendingRequest as P, type Channel as a, type ChannelUpdateResult as b };
import { TypedData } from 'viem';
interface AuthorizerSigner {
address: `0x${string}`;
signTypedData(params: {
domain: Record<string, unknown>;
types: TypedData;
primaryType: string;
message: Record<string, unknown>;
}): Promise<`0x${string}`>;
}
type ChannelState = {
balance: bigint;
totalClaimed: bigint;
withdrawRequestedAt: number;
refundNonce: bigint;
};
type ChannelConfig = {
payer: `0x${string}`;
payerAuthorizer: `0x${string}`;
receiver: `0x${string}`;
receiverAuthorizer: `0x${string}`;
token: `0x${string}`;
withdrawDelay: number;
salt: `0x${string}`;
};
type BatchSettlementErc3009Authorization = {
validAfter: string;
validBefore: string;
salt: `0x${string}`;
signature: `0x${string}`;
};
type BatchSettlementPermit2Authorization = {
from: `0x${string}`;
permitted: {
token: `0x${string}`;
amount: string;
};
spender: `0x${string}`;
nonce: string;
deadline: string;
witness: {
channelId: `0x${string}`;
};
signature: `0x${string}`;
};
type BatchSettlementAssetTransferMethod = "eip3009" | "permit2";
type BatchSettlementDepositAuthorization = {
erc3009Authorization: BatchSettlementErc3009Authorization;
permit2Authorization?: never;
} | {
erc3009Authorization?: never;
permit2Authorization: BatchSettlementPermit2Authorization;
};
type BatchSettlementDepositPayload = {
type: "deposit";
channelConfig: ChannelConfig;
voucher: BatchSettlementVoucherFields;
deposit: {
amount: string;
authorization: BatchSettlementDepositAuthorization;
};
};
type BatchSettlementVoucherPayload = {
type: "voucher";
channelConfig: ChannelConfig;
voucher: BatchSettlementVoucherFields;
};
type BatchSettlementRefundPayload = {
type: "refund";
channelConfig: ChannelConfig;
voucher: BatchSettlementVoucherFields;
amount?: string;
};
type BatchSettlementVoucherFields = {
channelId: `0x${string}`;
maxClaimableAmount: string;
signature: `0x${string}`;
};
type BatchSettlementVoucherClaim = {
voucher: {
channel: ChannelConfig;
maxClaimableAmount: string;
};
signature: `0x${string}`;
totalClaimed: string;
};
type BatchSettlementChannelStateExtra = {
channelId: `0x${string}`;
balance: string;
totalClaimed: string;
withdrawRequestedAt: number;
refundNonce: string;
chargedCumulativeAmount?: string;
};
type BatchSettlementVoucherStateExtra = {
signedMaxClaimable?: string;
signature?: `0x${string}`;
};
type BatchSettlementPaymentRequirementsExtra = {
receiverAuthorizer: `0x${string}`;
withdrawDelay: number;
name: string;
version: string;
assetTransferMethod?: BatchSettlementAssetTransferMethod;
channelState?: BatchSettlementChannelStateExtra;
voucherState?: BatchSettlementVoucherStateExtra;
};
type FileChannelStorageOptions = {
/** Root directory; channels are stored under `{directory}/{client|server}/{channelId}.json`. */
directory: string;
};
type BatchSettlementPaymentResponseExtra = {
chargedAmount?: string;
channelState?: BatchSettlementChannelStateExtra;
voucherState?: BatchSettlementVoucherStateExtra;
};
type BatchSettlementClaimPayload = {
type: "claim";
claims: BatchSettlementVoucherClaim[];
claimAuthorizerSignature?: `0x${string}`;
};
type BatchSettlementSettlePayload = {
type: "settle";
receiver: `0x${string}`;
token: `0x${string}`;
};
type BatchSettlementEnrichedRefundPayload = BatchSettlementRefundPayload & {
amount: string;
refundNonce: string;
claims: BatchSettlementVoucherClaim[];
refundAuthorizerSignature?: `0x${string}`;
claimAuthorizerSignature?: `0x${string}`;
};
type BatchSettlementPayload = BatchSettlementDepositPayload | BatchSettlementVoucherPayload | BatchSettlementRefundPayload;
type BatchSettlementFacilitatorSettlePayload = BatchSettlementDepositPayload | BatchSettlementClaimPayload | BatchSettlementSettlePayload | BatchSettlementEnrichedRefundPayload;
/**
* Type guard for {@link BatchSettlementDepositPayload}.
*
* @param payload - Unknown payload to check.
* @returns True if `payload` is a deposit payload (carries `deposit` and `voucher`).
*/
declare function isBatchSettlementDepositPayload(payload: unknown): payload is BatchSettlementDepositPayload;
/**
* Type guard for {@link BatchSettlementVoucherPayload}.
*
* @param payload - Unknown payload to check.
* @returns True if `payload` is a voucher payload with channel and signature fields.
*/
declare function isBatchSettlementVoucherPayload(payload: unknown): payload is BatchSettlementVoucherPayload;
/**
* Type guard for {@link BatchSettlementRefundPayload}.
*
* @param payload - Unknown payload to check.
* @returns True if `payload` is a refund payload with channel config and voucher fields.
*/
declare function isBatchSettlementRefundPayload(payload: unknown): payload is BatchSettlementRefundPayload;
/**
* Type guard for {@link BatchSettlementClaimPayload}.
*
* @param payload - Unknown payload to check.
* @returns True if `payload` is a settle-action `claimWithSignature` payload.
*/
declare function isBatchSettlementClaimPayload(payload: unknown): payload is BatchSettlementClaimPayload;
/**
* Type guard for {@link BatchSettlementSettlePayload}.
*
* @param payload - Unknown payload to check.
* @returns True if `payload` is a settle-action `settle` payload.
*/
declare function isBatchSettlementSettlePayload(payload: unknown): payload is BatchSettlementSettlePayload;
/**
* Type guard for {@link BatchSettlementEnrichedRefundPayload}.
*
* @param payload - Unknown payload to check.
* @returns True if `payload` is a settle-action `refundWithSignature` payload.
*/
declare function isBatchSettlementEnrichedRefundPayload(payload: unknown): payload is BatchSettlementEnrichedRefundPayload;
export { type AuthorizerSigner as A, type BatchSettlementVoucherClaim as B, type ChannelConfig as C, type FileChannelStorageOptions as F, type BatchSettlementVoucherFields as a, type BatchSettlementChannelStateExtra as b, type BatchSettlementVoucherStateExtra as c, type ChannelState as d, type BatchSettlementDepositPayload as e, type BatchSettlementVoucherPayload as f, type BatchSettlementRefundPayload as g, type BatchSettlementErc3009Authorization as h, type BatchSettlementClaimPayload as i, type BatchSettlementEnrichedRefundPayload as j, type BatchSettlementPayload as k, type BatchSettlementSettlePayload as l, type BatchSettlementFacilitatorSettlePayload as m, type BatchSettlementPaymentRequirementsExtra as n, type BatchSettlementPaymentResponseExtra as o, isBatchSettlementDepositPayload as p, isBatchSettlementVoucherPayload as q, isBatchSettlementRefundPayload as r, isBatchSettlementClaimPayload as s, isBatchSettlementSettlePayload as t, isBatchSettlementEnrichedRefundPayload as u };
// src/shared/defaultAssets.ts
var DEFAULT_STABLECOINS = {
"eip155:8453": {
address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
name: "USD Coin",
version: "2",
decimals: 6
},
// Base mainnet USDC
"eip155:84532": {
address: "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
name: "USDC",
version: "2",
decimals: 6
},
// Base Sepolia USDC
"eip155:4326": {
address: "0xFAfDdbb3FC7688494971a79cc65DCa3EF82079E7",
name: "MegaUSD",
version: "1",
decimals: 18,
assetTransferMethod: "permit2",
supportsEip2612: true
},
// MegaETH mainnet MegaUSD (no EIP-3009, supports EIP-2612)
"eip155:143": {
address: "0x754704Bc059F8C67012fEd69BC8A327a5aafb603",
name: "USD Coin",
version: "2",
decimals: 6
},
// Monad mainnet USDC
"eip155:988": {
address: "0x779Ded0c9e1022225f8E0630b35a9b54bE713736",
name: "USDT0",
version: "1",
decimals: 6
},
// Stable mainnet USDT0
"eip155:2201": {
address: "0x78Cf24370174180738C5B8E352B6D14c83a6c9A9",
name: "USDT0",
version: "1",
decimals: 6
},
// Stable testnet USDT0
"eip155:137": {
address: "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",
name: "USD Coin",
version: "2",
decimals: 6
},
// Polygon mainnet USDC
"eip155:42161": {
address: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
name: "USD Coin",
version: "2",
decimals: 6
},
// Arbitrum One USDC
"eip155:421614": {
address: "0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d",
name: "USD Coin",
version: "2",
decimals: 6
},
// Arbitrum Sepolia USDC
"eip155:31612": {
address: "0xdD468A1DDc392dcdbEf6db6e34E89AA338F9F186",
name: "Mezo USD",
version: "1",
decimals: 18,
assetTransferMethod: "permit2",
supportsEip2612: true
},
// Mezo mainnet mUSD (no EIP-3009, supports EIP-2612)
"eip155:31611": {
address: "0x118917a40FAF1CD7a13dB0Ef56C86De7973Ac503",
name: "Mezo USD",
version: "1",
decimals: 18,
assetTransferMethod: "permit2",
supportsEip2612: true
},
// Mezo Testnet mUSD (no EIP-3009, supports EIP-2612)
"eip155:723487": {
address: "0x33ad9e4BD16B69B5BFdED37D8B5D9fF9aba014Fb",
name: "Stable Coin",
version: "1",
decimals: 6,
assetTransferMethod: "permit2",
supportsEip2612: true
},
// Radius Network SBC (no EIP-3009, supports EIP-2612)
"eip155:72344": {
address: "0x33ad9e4BD16B69B5BFdED37D8B5D9fF9aba014Fb",
name: "Stable Coin",
version: "1",
decimals: 6,
assetTransferMethod: "permit2",
supportsEip2612: true
},
// Radius Testnet SBC (no EIP-3009, supports EIP-2612)
"eip155:36900": {
address: "0x9cb8142aEBBcdc60AF7c97Af897A67A8f3CA71C2",
name: "USDC.e",
version: "2",
decimals: 6
},
// ADI Chain USDC.e (EIP-3009 supported)
"eip155:190415": {
address: "0x401eCb1D350407f13ba348573E5630B83638E30D",
name: "Bridged USDC",
version: "2",
decimals: 6
},
// HPP mainnet USDC.e
"eip155:181228": {
address: "0x401eCb1D350407f13ba348573E5630B83638E30D",
name: "Bridged USDC",
version: "2",
decimals: 6
},
// HPP Sepolia USDC.e
"eip155:50": {
address: "0xfA2958CB79b0491CC627c1557F441eF849Ca8eb1",
name: "USDC",
version: "2",
decimals: 6
},
// XDC Network mainnet USDC (Bridged USDC Standard, EIP-3009 supported)
"eip155:51": {
address: "0xb5AB69F7bBada22B28e79C8FFAECe55eF1c771D4",
name: "USDC",
version: "2",
decimals: 6
},
// XDC Apothem testnet USDC (Bridged USDC Standard, EIP-3009 supported)
"eip155:38833": {
address: "0xA5b8BF902b2844dA17d4506cc827F7F1681735E7",
name: "USDC",
version: "1",
decimals: 6,
assetTransferMethod: "permit2"
},
// Igra mainnet USDC (no EIP-3009, no EIP-2612)
"eip155:14": {
address: "0xe7cd86e13AC4309349F30B3435a9d337750fC82D",
name: "USD\u20AE0",
version: "1",
decimals: 6
},
// Flare mainnet USD₮0 (EIP-3009 supported)
"eip155:42220": {
address: "0xcebA9300f2b948710d2653dD7B07f33A8B32118C",
name: "USDC",
version: "2",
decimals: 6
},
// Celo mainnet USDC (EIP-3009 supported)
"eip155:11142220": {
address: "0x01C5C0122039549AD1493B8220cABEdD739BC44E",
name: "USDC",
version: "2",
decimals: 6
}
// Celo Sepolia testnet USDC (EIP-3009 supported)
};
function getDefaultAsset(network) {
const info = DEFAULT_STABLECOINS[network];
if (!info) {
throw new Error(`No default asset configured for network ${network}`);
}
return info;
}
export {
DEFAULT_STABLECOINS,
getDefaultAsset
};
//# sourceMappingURL=chunk-KTVL22S4.mjs.map
{"version":3,"sources":["../../src/shared/defaultAssets.ts"],"sourcesContent":["import type { Network } from \"@x402/core/types\";\n\n/**\n * Base stablecoin asset configuration shared across all EVM payment schemes.\n * Contains the core fields needed to identify and convert tokens.\n */\nexport type DefaultAssetInfo = {\n /** Token contract address */\n address: string;\n /** EIP-712 domain name (must match the token's domain separator) */\n name: string;\n /** EIP-712 domain version (must match the token's domain separator) */\n version: string;\n /** Token decimal places (typically 6 for USDC) */\n decimals: number;\n};\n\n/**\n * Extended asset configuration for the exact scheme.\n * Includes transfer method hints that control client-side behaviour.\n */\nexport type ExactDefaultAssetInfo = DefaultAssetInfo & {\n /**\n * Transfer method override: `\"permit2\"` for tokens that don't support EIP-3009.\n * Omit for EIP-3009 tokens (default behaviour).\n */\n assetTransferMethod?: string;\n /**\n * Set to `true` for permit2 tokens that implement EIP-2612 `permit()`.\n * Controls whether name/version are included in `extra` so the client can\n * sign a gasless EIP-2612 permit for Permit2 approval.\n */\n supportsEip2612?: boolean;\n};\n\n/**\n * Default stablecoins indexed by CAIP-2 network identifier.\n *\n * Each network has the right to determine its own default stablecoin that can\n * be expressed as a USD string by calling servers. See DEFAULT_ASSETS.md at the\n * repository root for how to add new chains.\n */\nexport const DEFAULT_STABLECOINS: Record<string, ExactDefaultAssetInfo> = {\n \"eip155:8453\": {\n address: \"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913\",\n name: \"USD Coin\",\n version: \"2\",\n decimals: 6,\n }, // Base mainnet USDC\n \"eip155:84532\": {\n address: \"0x036CbD53842c5426634e7929541eC2318f3dCF7e\",\n name: \"USDC\",\n version: \"2\",\n decimals: 6,\n }, // Base Sepolia USDC\n \"eip155:4326\": {\n address: \"0xFAfDdbb3FC7688494971a79cc65DCa3EF82079E7\",\n name: \"MegaUSD\",\n version: \"1\",\n decimals: 18,\n assetTransferMethod: \"permit2\",\n supportsEip2612: true,\n }, // MegaETH mainnet MegaUSD (no EIP-3009, supports EIP-2612)\n \"eip155:143\": {\n address: \"0x754704Bc059F8C67012fEd69BC8A327a5aafb603\",\n name: \"USD Coin\",\n version: \"2\",\n decimals: 6,\n }, // Monad mainnet USDC\n \"eip155:988\": {\n address: \"0x779Ded0c9e1022225f8E0630b35a9b54bE713736\",\n name: \"USDT0\",\n version: \"1\",\n decimals: 6,\n }, // Stable mainnet USDT0\n \"eip155:2201\": {\n address: \"0x78Cf24370174180738C5B8E352B6D14c83a6c9A9\",\n name: \"USDT0\",\n version: \"1\",\n decimals: 6,\n }, // Stable testnet USDT0\n \"eip155:137\": {\n address: \"0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359\",\n name: \"USD Coin\",\n version: \"2\",\n decimals: 6,\n }, // Polygon mainnet USDC\n \"eip155:42161\": {\n address: \"0xaf88d065e77c8cC2239327C5EDb3A432268e5831\",\n name: \"USD Coin\",\n version: \"2\",\n decimals: 6,\n }, // Arbitrum One USDC\n \"eip155:421614\": {\n address: \"0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d\",\n name: \"USD Coin\",\n version: \"2\",\n decimals: 6,\n }, // Arbitrum Sepolia USDC\n \"eip155:31612\": {\n address: \"0xdD468A1DDc392dcdbEf6db6e34E89AA338F9F186\",\n name: \"Mezo USD\",\n version: \"1\",\n decimals: 18,\n assetTransferMethod: \"permit2\",\n supportsEip2612: true,\n }, // Mezo mainnet mUSD (no EIP-3009, supports EIP-2612)\n \"eip155:31611\": {\n address: \"0x118917a40FAF1CD7a13dB0Ef56C86De7973Ac503\",\n name: \"Mezo USD\",\n version: \"1\",\n decimals: 18,\n assetTransferMethod: \"permit2\",\n supportsEip2612: true,\n }, // Mezo Testnet mUSD (no EIP-3009, supports EIP-2612)\n \"eip155:723487\": {\n address: \"0x33ad9e4BD16B69B5BFdED37D8B5D9fF9aba014Fb\",\n name: \"Stable Coin\",\n version: \"1\",\n decimals: 6,\n assetTransferMethod: \"permit2\",\n supportsEip2612: true,\n }, // Radius Network SBC (no EIP-3009, supports EIP-2612)\n \"eip155:72344\": {\n address: \"0x33ad9e4BD16B69B5BFdED37D8B5D9fF9aba014Fb\",\n name: \"Stable Coin\",\n version: \"1\",\n decimals: 6,\n assetTransferMethod: \"permit2\",\n supportsEip2612: true,\n }, // Radius Testnet SBC (no EIP-3009, supports EIP-2612)\n \"eip155:36900\": {\n address: \"0x9cb8142aEBBcdc60AF7c97Af897A67A8f3CA71C2\",\n name: \"USDC.e\",\n version: \"2\",\n decimals: 6,\n }, // ADI Chain USDC.e (EIP-3009 supported)\n \"eip155:190415\": {\n address: \"0x401eCb1D350407f13ba348573E5630B83638E30D\",\n name: \"Bridged USDC\",\n version: \"2\",\n decimals: 6,\n }, // HPP mainnet USDC.e\n \"eip155:181228\": {\n address: \"0x401eCb1D350407f13ba348573E5630B83638E30D\",\n name: \"Bridged USDC\",\n version: \"2\",\n decimals: 6,\n }, // HPP Sepolia USDC.e\n \"eip155:50\": {\n address: \"0xfA2958CB79b0491CC627c1557F441eF849Ca8eb1\",\n name: \"USDC\",\n version: \"2\",\n decimals: 6,\n }, // XDC Network mainnet USDC (Bridged USDC Standard, EIP-3009 supported)\n \"eip155:51\": {\n address: \"0xb5AB69F7bBada22B28e79C8FFAECe55eF1c771D4\",\n name: \"USDC\",\n version: \"2\",\n decimals: 6,\n }, // XDC Apothem testnet USDC (Bridged USDC Standard, EIP-3009 supported)\n \"eip155:38833\": {\n address: \"0xA5b8BF902b2844dA17d4506cc827F7F1681735E7\",\n name: \"USDC\",\n version: \"1\",\n decimals: 6,\n assetTransferMethod: \"permit2\",\n }, // Igra mainnet USDC (no EIP-3009, no EIP-2612)\n \"eip155:14\": {\n address: \"0xe7cd86e13AC4309349F30B3435a9d337750fC82D\",\n name: \"USD\\u20AE0\",\n version: \"1\",\n decimals: 6,\n }, // Flare mainnet USD₮0 (EIP-3009 supported)\n \"eip155:42220\": {\n address: \"0xcebA9300f2b948710d2653dD7B07f33A8B32118C\",\n name: \"USDC\",\n version: \"2\",\n decimals: 6,\n }, // Celo mainnet USDC (EIP-3009 supported)\n \"eip155:11142220\": {\n address: \"0x01C5C0122039549AD1493B8220cABEdD739BC44E\",\n name: \"USDC\",\n version: \"2\",\n decimals: 6,\n }, // Celo Sepolia testnet USDC (EIP-3009 supported)\n};\n\n/**\n * Look up the default stablecoin for a network.\n *\n * @param network - CAIP-2 network identifier (e.g. \"eip155:8453\")\n * @returns The default asset info\n * @throws If no default asset is configured for the network\n */\nexport function getDefaultAsset(network: Network): ExactDefaultAssetInfo {\n const info = DEFAULT_STABLECOINS[network];\n if (!info) {\n throw new Error(`No default asset configured for network ${network}`);\n }\n return info;\n}\n"],"mappings":";AA0CO,IAAM,sBAA6D;AAAA,EACxE,eAAe;AAAA,IACb,SAAS;AAAA,IACT,MAAM;AAAA,IACN,SAAS;AAAA,IACT,UAAU;AAAA,EACZ;AAAA;AAAA,EACA,gBAAgB;AAAA,IACd,SAAS;AAAA,IACT,MAAM;AAAA,IACN,SAAS;AAAA,IACT,UAAU;AAAA,EACZ;AAAA;AAAA,EACA,eAAe;AAAA,IACb,SAAS;AAAA,IACT,MAAM;AAAA,IACN,SAAS;AAAA,IACT,UAAU;AAAA,IACV,qBAAqB;AAAA,IACrB,iBAAiB;AAAA,EACnB;AAAA;AAAA,EACA,cAAc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AAM;AAAA,IACN,SAAS;AAAA,IACT,UAAU;AAAA,EACZ;AAAA;AAAA,EACA,iBAAiB;AAAA,IACf,SAAS;AAAA,IACT,MAAM;AAAA,IACN,SAAS;AAAA,IACT,UAAU;AAAA,EACZ;AAAA;AAAA,EACA,iBAAiB;AAAA,IACf,SAAS;AAAA,IACT,MAAM;AAAA,IACN,SAAS;AAAA,IACT,UAAU;AAAA,EACZ;AAAA;AAAA,EACA,aAAa;AAAA,IACX,SAAS;AAAA,IACT,MAAM;AAAA,IACN,SAAS;AAAA,IACT,UAAU;AAAA,EACZ;AAAA;AAAA,EACA,aAAa;AAAA,IACX,SAAS;AAAA,IACT,MAAM;AAAA,IACN,SAAS;AAAA,IACT,UAAU;AAAA,EACZ;AAAA;AAAA,EACA,gBAAgB;AAAA,IACd,SAAS;AAAA,IACT,MAAM;AAAA,IACN,SAAS;AAAA,IACT,UAAU;AAAA,IACV,qBAAqB;AAAA,EACvB;AAAA;AAAA,EACA,aAAa;AAAA,IACX,SAAS;AAAA,IACT,MAAM;AAAA,IACN,SAAS;AAAA,IACT,UAAU;AAAA,EACZ;AAAA;AAAA,EACA,gBAAgB;AAAA,IACd,SAAS;AAAA,IACT,MAAM;AAAA,IACN,SAAS;AAAA,IACT,UAAU;AAAA,EACZ;AAAA;AAAA,EACA,mBAAmB;AAAA,IACjB,SAAS;AAAA,IACT,MAAM;AAAA,IACN,SAAS;AAAA,IACT,UAAU;AAAA,EACZ;AAAA;AACF;AASO,SAAS,gBAAgB,SAAyC;AACvE,QAAM,OAAO,oBAAoB,OAAO;AACxC,MAAI,CAAC,MAAM;AACT,UAAM,IAAI,MAAM,2CAA2C,OAAO,EAAE;AAAA,EACtE;AACA,SAAO;AACT;","names":[]}
import { PaymentRequirements, SettleResponse, SchemeNetworkClient, SchemeClientHooks, PaymentPayloadContext, PaymentPayloadResult, PaymentRequired } from '@x402/core/types';
import { C as ClientEvmSigner } from './signer-B127taDR.mjs';
import { C as ChannelConfig } from './types-DIt9uAUy.mjs';
import { c as EvmSchemeOptions } from './rpc-DULZzRne.mjs';
import { B as BatchSettlementClientContext, C as ClientChannelStorage } from './storage-BFpn16ZW.mjs';
/**
* Caller-tunable policy controlling how the client sizes channel deposits.
*/
interface BatchSettlementDepositPolicy {
depositMultiplier?: number;
}
/**
* Return shape for custom deposit sizing.
*/
type BatchSettlementDepositStrategyResult = string | bigint | false | undefined;
/**
* Information supplied before the client signs a deposit authorization.
*/
interface BatchSettlementDepositStrategyContext {
paymentRequirements: PaymentRequirements;
channelConfig: ChannelConfig;
channelId: `0x${string}`;
clientContext: BatchSettlementClientContext;
requestAmount: string;
maxClaimableAmount: string;
currentBalance: string;
minimumDepositAmount: string;
depositAmount: string;
}
/**
* Custom deposit sizing callback for initial deposits and top-ups.
*/
type BatchSettlementDepositStrategy = (context: BatchSettlementDepositStrategyContext) => BatchSettlementDepositStrategyResult | Promise<BatchSettlementDepositStrategyResult>;
/**
* Full options object accepted by `BatchSettlementEvmScheme`. Either this or a
* bare {@link BatchSettlementDepositPolicy} can be passed as the second
* constructor argument.
*/
interface BatchSettlementEvmSchemeOptions {
depositPolicy?: BatchSettlementDepositPolicy;
/** Optional callback for app-specific deposit sizing or skipping. */
depositStrategy?: BatchSettlementDepositStrategy;
storage?: ClientChannelStorage;
salt?: `0x${string}`;
payerAuthorizer?: `0x${string}`;
rpcUrl?: string;
/** When set, EIP-712 vouchers are signed with this key; deposits still use the main `signer`. */
voucherSigner?: ClientEvmSigner;
}
/**
* Resolved options after merging defaults — used internally by the scheme,
* recovery, and refund modules.
*/
interface ResolvedClientOptions {
depositPolicy?: BatchSettlementDepositPolicy;
depositStrategy?: BatchSettlementDepositStrategy;
storage: ClientChannelStorage;
salt: `0x${string}`;
payerAuthorizer?: `0x${string}`;
voucherSigner?: ClientEvmSigner;
extensionRpcOptions?: EvmSchemeOptions;
}
/**
* Discriminates a full options object from a bare deposit-policy object.
*
* @param o - Constructor argument that may be options, deposit policy only, or undefined.
* @returns `true` when `o` is a {@link BatchSettlementEvmSchemeOptions} object.
*/
declare function isBatchSettlementEvmSchemeOptions(o: BatchSettlementEvmSchemeOptions | BatchSettlementDepositPolicy | undefined): o is BatchSettlementEvmSchemeOptions;
/**
* Normalises the constructor's second argument into a uniform options shape.
*
* @param second - Optional second constructor argument (options or deposit policy).
* @returns Resolved storage, salt, deposit policy, and optional payer authorizer.
*/
declare function resolveClientOptions(second?: BatchSettlementEvmSchemeOptions | BatchSettlementDepositPolicy): ResolvedClientOptions;
/**
* Validates a {@link BatchSettlementDepositPolicy}, throwing on invalid fields.
*
* @param policy - The policy to validate (no-op when undefined).
*/
declare function validateDepositPolicy(policy: BatchSettlementDepositPolicy | undefined): void;
/**
* Computes the deposit amount based on the deposit multiplier.
*
* @param policy - Deposit policy controlling multiplier (may be undefined).
* @param requestAmount - Amount requested for this operation, in token base units.
* @returns Deposit amount string in token base units.
*/
declare function depositAmountForRequest(policy: BatchSettlementDepositPolicy | undefined, requestAmount: bigint): string;
/**
* Runtime dependency bag shared by every storage-bound client helper (channel,
* recovery, refund) and the {@link BatchSettlementEvmScheme} class.
*/
interface BatchSettlementClientDeps {
signer: ClientEvmSigner;
storage: ClientChannelStorage;
salt: `0x${string}`;
payerAuthorizer?: `0x${string}`;
voucherSigner?: ClientEvmSigner;
}
/**
* Constructs the immutable {@link ChannelConfig} from payment requirements and
* a client deps bag (signer, salt, optional payerAuthorizer / voucherSigner).
*
* @param deps - Client identity inputs.
* @param paymentRequirements - Server payment requirements providing receiver, asset, and extra fields.
* @returns The ChannelConfig that uniquely identifies this payment channel.
*/
declare function buildChannelConfig(deps: BatchSettlementClientDeps, paymentRequirements: PaymentRequirements): ChannelConfig;
/**
* Updates local channel state from a parsed `SettleResponse`.
*
* @param storage - Client channel storage.
* @param settle - The parsed settle response.
*/
declare function processSettleResponse(storage: ClientChannelStorage, settle: SettleResponse): Promise<void>;
/**
* Reconciles local channel state with the outcome of a cooperative refund.
*
* Deletes the channel record when the post-refund balance is zero (full refund),
* otherwise updates local state from the server snapshot.
*
* @param storage - Client channel storage.
* @param channelKey - Lowercased channel id used as the storage key.
* @param settleExtra - The `extra` block from the refund settle response.
*/
declare function updateChannelAfterRefund(storage: ClientChannelStorage, channelKey: string, settleExtra: Record<string, unknown>): Promise<void>;
/**
* Processes the `PAYMENT-RESPONSE` header after a successful request.
*
* Decodes the header into a `SettleResponse` and delegates to
* {@link processSettleResponse}.
*
* @param storage - Client channel storage.
* @param getHeader - Function to retrieve a response header by name.
*/
declare function processPaymentResponse(storage: ClientChannelStorage, getHeader: (name: string) => string | null | undefined): Promise<void>;
/**
* Recovers a channel record from onchain state (useful after a cold start or
* channel record loss).
*
* @param deps - Signer + storage + identity inputs.
* @param paymentRequirements - Server payment requirements used to derive the ChannelConfig.
* @returns The recovered client context.
*/
declare function recoverChannel(deps: BatchSettlementClientDeps, paymentRequirements: PaymentRequirements): Promise<BatchSettlementClientContext>;
/**
* Reads `channels(channelId)` returning `[balance, totalClaimed]`.
*
* @param signer - Signer providing `readContract`.
* @param channelId - The `bytes32` channel id to query.
* @returns Tuple of `[balance, totalClaimed]` as bigints.
*/
declare function readChannelBalanceAndTotalClaimed(signer: ClientEvmSigner, channelId: `0x${string}`): Promise<[bigint, bigint]>;
/**
* Returns whether a local channel record exists for the given channel.
*
* @param storage - Client channel storage.
* @param channelId - The channel identifier to check.
* @returns `true` when a channel record is stored.
*/
declare function hasChannel(storage: ClientChannelStorage, channelId: string): Promise<boolean>;
/**
* Returns the local channel context for a channel, if present.
*
* @param storage - Client channel storage.
* @param channelId - The channel identifier.
* @returns Stored context or `undefined`.
*/
declare function getChannel(storage: ClientChannelStorage, channelId: string): Promise<BatchSettlementClientContext | undefined>;
/**
* Caller-facing options for {@link refundChannel}.
*/
interface RefundOptions {
/** Token base units to refund; omit for a full refund (drains remaining balance). */
amount?: string;
/** Custom fetch implementation (defaults to `globalThis.fetch`). */
fetch?: typeof fetch;
}
/**
* Sends a cooperative refund request to the channel that backs `url`.
*
* Flow:
* 1. Probe the URL with `GET` (no payment) to obtain the route's payment requirements.
* 2. Build the `ChannelConfig` and resolve the local session (or recover it).
* 3. Sign a zero-charge refund voucher (`maxClaimableAmount = chargedCumulativeAmount`).
* 4. Send the voucher via `PAYMENT-SIGNATURE`. On a corrective 402, run the
* standard recovery path and retry once.
* 5. Return the parsed `SettleResponse` from the server.
*
* @param ctx - Identity inputs (storage, signers, salt, payerAuthorizer).
* @param url - Any protected route on the channel to refund (the resource handler is bypassed).
* @param options - Optional `amount` (partial refund) and `fetch` override.
* @returns The settle response describing the refund outcome.
* @throws When the probe fails, the receiver lacks an authorizer, or recovery fails.
*/
declare function refundChannel(ctx: BatchSettlementClientDeps, url: string, options?: RefundOptions): Promise<SettleResponse>;
/**
* Client-side implementation of the `batch-settlement` scheme for EVM networks.
*
* Builds payment payloads (deposit + voucher or voucher-only), processes server
* responses to update local session state via {@link processSettleResponse},
* handles corrective 402 resynchronisation via
* {@link processCorrectivePaymentRequired}, and supports on-demand cooperative
* refund requests via {@link refundChannel}.
*/
declare class BatchSettlementEvmScheme implements SchemeNetworkClient {
private readonly signer;
readonly scheme: "batch-settlement";
readonly schemeHooks: SchemeClientHooks;
private readonly storage;
private readonly depositPolicy;
private readonly depositStrategy;
private readonly salt;
private readonly payerAuthorizer;
private readonly voucherSigner;
private readonly extensionRpcOptions;
/**
* Constructs a batched client scheme.
*
* @param signer - Client EVM wallet used for signing vouchers and ERC-3009 authorizations.
* @param optionsOrPolicy - Either a full options object or a bare deposit-policy.
*/
constructor(signer: ClientEvmSigner, optionsOrPolicy?: BatchSettlementEvmSchemeOptions | BatchSettlementDepositPolicy);
/**
* Creates the payment payload for a batched request.
*
* If the channel has no onchain deposit (or needs a top-up), builds an
* ERC-3009 deposit payload bundled with a voucher. Otherwise, signs and
* returns a voucher-only payload.
*
* @param x402Version - Protocol version for the payload envelope.
* @param paymentRequirements - Server payment requirements (scheme, network, asset, amount).
* @param context - Optional payment payload context with extension hints.
* @returns A {@link PaymentPayloadResult} ready to be sent as the `X-PAYMENT` header.
*/
createPaymentPayload(x402Version: number, paymentRequirements: PaymentRequirements, context?: PaymentPayloadContext): Promise<PaymentPayloadResult>;
/**
* Sends a cooperative refund request.
*
* @param url - The route URL backing the channel to refund.
* @param options - Optional `amount` (partial refund) and `fetch` override.
* @returns The settle response describing the refund outcome.
*/
refund(url: string, options?: RefundOptions): Promise<SettleResponse>;
/**
* Updates local channel state from a settle response.
*
* @param settle - The parsed settle response from the server.
* @returns Resolves when local channel state has been updated.
*/
processSettleResponse(settle: SettleResponse): Promise<void>;
/**
* Resyncs local channel state from a corrective 402 response.
*
* @param paymentRequired - The decoded 402 response body.
* @returns `true` if local state was successfully resynced and a retry is warranted.
*/
processCorrectivePaymentRequired(paymentRequired: PaymentRequired): Promise<boolean>;
/**
* Builds the immutable {@link ChannelConfig} for a given set of payment
* requirements, using the scheme's own signer and salt.
*
* @param paymentRequirements - Server payment requirements for the channel.
* @returns The channel config that uniquely identifies the payment channel.
*/
buildChannelConfig(paymentRequirements: PaymentRequirements): ChannelConfig;
/**
* Resolves the deposit amount after applying the optional custom strategy.
*
* @param context - Deposit attempt context exposed to the strategy.
* @returns The deposit amount to sign, or `false` to skip this deposit attempt.
*/
private resolveDepositAmount;
/**
* Normalizes and validates a strategy-provided base-unit deposit amount.
*
* @param value - Strategy-provided string or bigint amount.
* @returns Normalized decimal string.
*/
private normalizeStrategyDepositAmount;
/**
* Signs a voucher-only payment payload for the current channel.
*
* @param x402Version - Protocol version for the payload envelope.
* @param channelId - Channel identifier for the voucher.
* @param maxClaimableAmount - Cumulative ceiling for the voucher.
* @param network - CAIP-2 network identifier.
* @param config - Immutable channel configuration.
* @returns Voucher-only payment payload.
*/
private createVoucherPayload;
/**
* Bundles the class state into the {@link BatchSettlementClientDeps} shape
* consumed by the `channel`, `recovery`, and `refund` modules.
*
* @returns Client deps wrapping the scheme's own signer and storage.
*/
private deps;
}
export { type BatchSettlementClientDeps as B, type RefundOptions as R, BatchSettlementEvmScheme as a, type BatchSettlementDepositPolicy as b, type BatchSettlementDepositStrategy as c, type BatchSettlementDepositStrategyContext as d, type BatchSettlementDepositStrategyResult as e, type BatchSettlementEvmSchemeOptions as f, depositAmountForRequest as g, resolveClientOptions as h, isBatchSettlementEvmSchemeOptions as i, type ResolvedClientOptions as j, buildChannelConfig as k, getChannel as l, hasChannel as m, processSettleResponse as n, readChannelBalanceAndTotalClaimed as o, processPaymentResponse as p, recoverChannel as q, refundChannel as r, updateChannelAfterRefund as u, validateDepositPolicy as v };
import { C as ChannelConfig } from './types-DIt9uAUy.mjs';
interface Channel {
channelId: string;
channelConfig: ChannelConfig;
chargedCumulativeAmount: string;
signedMaxClaimable: string;
signature: string;
balance: string;
totalClaimed: string;
withdrawRequestedAt: number;
refundNonce: number;
onchainSyncedAt?: number;
lastRequestTimestamp: number;
pendingRequest?: PendingRequest;
}
interface PendingRequest {
pendingId: string;
signedMaxClaimable: string;
expiresAt: number;
}
interface ChannelUpdateResult {
channel: Channel | undefined;
status: "updated" | "unchanged" | "deleted";
}
interface ChannelStorage {
get(channelId: string): Promise<Channel | undefined>;
list(): Promise<Channel[]>;
/**
* Atomically inspects and mutates a channel record.
*
* Implementations must guarantee that no concurrent mutation can interleave between
* reading `current` and writing the callback result for all application instances that
* share the backend. The in-memory backend only provides this guarantee inside one JS
* runtime; production multi-instance deployments need storage with backend-level atomic
* conditional mutation, such as Redis/Valkey Lua scripts, SQL transactions, or Durable Objects.
*
* @param channelId - The channel identifier.
* @param update - Mutation callback. Return `undefined` to delete, or `current` to leave unchanged.
* @returns The final stored channel and whether storage updated, stayed unchanged, or deleted.
*/
updateChannel(channelId: string, update: (current: Channel | undefined) => Channel | undefined): Promise<ChannelUpdateResult>;
}
/**
* In-memory {@link ChannelStorage} backed by a Map keyed by `channelId`.
*/
declare class InMemoryChannelStorage implements ChannelStorage {
private readonly channels;
private readonly channelLocks;
/**
* Returns the channel record for a channel, if present.
*
* @param channelId - The channel identifier.
* @returns The channel record or undefined when not found.
*/
get(channelId: string): Promise<Channel | undefined>;
/**
* Lists all stored channel records.
*
* @returns All channel records in storage.
*/
list(): Promise<Channel[]>;
/**
* Atomically inspects and mutates a channel record while holding a per-channel lock.
*
* @param channelId - The channel identifier.
* @param update - Mutation callback. Return `undefined` to delete, or `current` to leave unchanged.
* @returns The final stored channel and whether storage updated, stayed unchanged, or deleted.
*/
updateChannel(channelId: string, update: (current: Channel | undefined) => Channel | undefined): Promise<ChannelUpdateResult>;
/**
* Runs `fn` after any prior locked work for the same channel key has finished.
*
* @param key - Lowercased channel id used as the lock key.
* @param fn - Async work to run while holding the logical per-channel lock.
* @returns The resolved result of `fn`.
*/
private withChannelLock;
}
export { type ChannelStorage as C, InMemoryChannelStorage as I, type PendingRequest as P, type Channel as a, type ChannelUpdateResult as b };
import { TypedData } from 'viem';
interface AuthorizerSigner {
address: `0x${string}`;
signTypedData(params: {
domain: Record<string, unknown>;
types: TypedData;
primaryType: string;
message: Record<string, unknown>;
}): Promise<`0x${string}`>;
}
type ChannelState = {
balance: bigint;
totalClaimed: bigint;
withdrawRequestedAt: number;
refundNonce: bigint;
};
type ChannelConfig = {
payer: `0x${string}`;
payerAuthorizer: `0x${string}`;
receiver: `0x${string}`;
receiverAuthorizer: `0x${string}`;
token: `0x${string}`;
withdrawDelay: number;
salt: `0x${string}`;
};
type BatchSettlementErc3009Authorization = {
validAfter: string;
validBefore: string;
salt: `0x${string}`;
signature: `0x${string}`;
};
type BatchSettlementPermit2Authorization = {
from: `0x${string}`;
permitted: {
token: `0x${string}`;
amount: string;
};
spender: `0x${string}`;
nonce: string;
deadline: string;
witness: {
channelId: `0x${string}`;
};
signature: `0x${string}`;
};
type BatchSettlementAssetTransferMethod = "eip3009" | "permit2";
type BatchSettlementDepositAuthorization = {
erc3009Authorization: BatchSettlementErc3009Authorization;
permit2Authorization?: never;
} | {
erc3009Authorization?: never;
permit2Authorization: BatchSettlementPermit2Authorization;
};
type BatchSettlementDepositPayload = {
type: "deposit";
channelConfig: ChannelConfig;
voucher: BatchSettlementVoucherFields;
deposit: {
amount: string;
authorization: BatchSettlementDepositAuthorization;
};
};
type BatchSettlementVoucherPayload = {
type: "voucher";
channelConfig: ChannelConfig;
voucher: BatchSettlementVoucherFields;
};
type BatchSettlementRefundPayload = {
type: "refund";
channelConfig: ChannelConfig;
voucher: BatchSettlementVoucherFields;
amount?: string;
};
type BatchSettlementVoucherFields = {
channelId: `0x${string}`;
maxClaimableAmount: string;
signature: `0x${string}`;
};
type BatchSettlementVoucherClaim = {
voucher: {
channel: ChannelConfig;
maxClaimableAmount: string;
};
signature: `0x${string}`;
totalClaimed: string;
};
type BatchSettlementChannelStateExtra = {
channelId: `0x${string}`;
balance: string;
totalClaimed: string;
withdrawRequestedAt: number;
refundNonce: string;
chargedCumulativeAmount?: string;
};
type BatchSettlementVoucherStateExtra = {
signedMaxClaimable?: string;
signature?: `0x${string}`;
};
type BatchSettlementPaymentRequirementsExtra = {
receiverAuthorizer: `0x${string}`;
withdrawDelay: number;
name: string;
version: string;
assetTransferMethod?: BatchSettlementAssetTransferMethod;
channelState?: BatchSettlementChannelStateExtra;
voucherState?: BatchSettlementVoucherStateExtra;
};
type FileChannelStorageOptions = {
/** Root directory; channels are stored under `{directory}/{client|server}/{channelId}.json`. */
directory: string;
};
type BatchSettlementPaymentResponseExtra = {
chargedAmount?: string;
channelState?: BatchSettlementChannelStateExtra;
voucherState?: BatchSettlementVoucherStateExtra;
};
type BatchSettlementClaimPayload = {
type: "claim";
claims: BatchSettlementVoucherClaim[];
claimAuthorizerSignature?: `0x${string}`;
};
type BatchSettlementSettlePayload = {
type: "settle";
receiver: `0x${string}`;
token: `0x${string}`;
};
type BatchSettlementEnrichedRefundPayload = BatchSettlementRefundPayload & {
amount: string;
refundNonce: string;
claims: BatchSettlementVoucherClaim[];
refundAuthorizerSignature?: `0x${string}`;
claimAuthorizerSignature?: `0x${string}`;
};
type BatchSettlementPayload = BatchSettlementDepositPayload | BatchSettlementVoucherPayload | BatchSettlementRefundPayload;
type BatchSettlementFacilitatorSettlePayload = BatchSettlementDepositPayload | BatchSettlementClaimPayload | BatchSettlementSettlePayload | BatchSettlementEnrichedRefundPayload;
/**
* Type guard for {@link BatchSettlementDepositPayload}.
*
* @param payload - Unknown payload to check.
* @returns True if `payload` is a deposit payload (carries `deposit` and `voucher`).
*/
declare function isBatchSettlementDepositPayload(payload: unknown): payload is BatchSettlementDepositPayload;
/**
* Type guard for {@link BatchSettlementVoucherPayload}.
*
* @param payload - Unknown payload to check.
* @returns True if `payload` is a voucher payload with channel and signature fields.
*/
declare function isBatchSettlementVoucherPayload(payload: unknown): payload is BatchSettlementVoucherPayload;
/**
* Type guard for {@link BatchSettlementRefundPayload}.
*
* @param payload - Unknown payload to check.
* @returns True if `payload` is a refund payload with channel config and voucher fields.
*/
declare function isBatchSettlementRefundPayload(payload: unknown): payload is BatchSettlementRefundPayload;
/**
* Type guard for {@link BatchSettlementClaimPayload}.
*
* @param payload - Unknown payload to check.
* @returns True if `payload` is a settle-action `claimWithSignature` payload.
*/
declare function isBatchSettlementClaimPayload(payload: unknown): payload is BatchSettlementClaimPayload;
/**
* Type guard for {@link BatchSettlementSettlePayload}.
*
* @param payload - Unknown payload to check.
* @returns True if `payload` is a settle-action `settle` payload.
*/
declare function isBatchSettlementSettlePayload(payload: unknown): payload is BatchSettlementSettlePayload;
/**
* Type guard for {@link BatchSettlementEnrichedRefundPayload}.
*
* @param payload - Unknown payload to check.
* @returns True if `payload` is a settle-action `refundWithSignature` payload.
*/
declare function isBatchSettlementEnrichedRefundPayload(payload: unknown): payload is BatchSettlementEnrichedRefundPayload;
export { type AuthorizerSigner as A, type BatchSettlementVoucherClaim as B, type ChannelConfig as C, type FileChannelStorageOptions as F, type BatchSettlementVoucherFields as a, type BatchSettlementChannelStateExtra as b, type BatchSettlementVoucherStateExtra as c, type ChannelState as d, type BatchSettlementDepositPayload as e, type BatchSettlementVoucherPayload as f, type BatchSettlementRefundPayload as g, type BatchSettlementErc3009Authorization as h, type BatchSettlementClaimPayload as i, type BatchSettlementEnrichedRefundPayload as j, type BatchSettlementPayload as k, type BatchSettlementSettlePayload as l, type BatchSettlementFacilitatorSettlePayload as m, type BatchSettlementPaymentRequirementsExtra as n, type BatchSettlementPaymentResponseExtra as o, isBatchSettlementDepositPayload as p, isBatchSettlementVoucherPayload as q, isBatchSettlementRefundPayload as r, isBatchSettlementClaimPayload as s, isBatchSettlementSettlePayload as t, isBatchSettlementEnrichedRefundPayload as u };

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display