@veil-cash/sdk 0.6.4 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { Buffer } from 'buffer';
2
+ import { SettleResponse, PaymentRequired, PaymentRequirements } from '@x402/core/types';
2
3
  import MerkleTree from 'fixed-merkle-tree-legacy';
3
4
 
4
5
  /**
@@ -285,9 +286,12 @@ interface RelayExtData {
285
286
  */
286
287
  interface RelayMetadata {
287
288
  amount?: string;
289
+ amountAtomic?: string;
288
290
  recipient?: string;
289
291
  inputUtxoCount?: number;
290
292
  outputUtxoCount?: number;
293
+ x402?: boolean;
294
+ payerIndex?: string;
291
295
  }
292
296
  /**
293
297
  * Request body for relay service
@@ -349,6 +353,8 @@ interface BuildWithdrawProofOptions {
349
353
  pool?: RelayPool;
350
354
  /** Optional RPC URL */
351
355
  rpcUrl?: string;
356
+ /** Optional relay URL */
357
+ relayUrl?: string;
352
358
  /**
353
359
  * Optional proving key directory/base URL or resolver.
354
360
  *
@@ -914,31 +920,6 @@ declare function getQueueBalance(options: {
914
920
  rpcUrl?: string;
915
921
  onProgress?: ProgressCallback;
916
922
  }): Promise<QueueBalanceResult>;
917
- /**
918
- * Get remaining daily free deposits for an address.
919
- * Returns 0 if the queue contract has not been upgraded to V3 yet
920
- * or if the daily free feature is disabled.
921
- *
922
- * @param options - Query options
923
- * @param options.address - Depositor address to check
924
- * @param options.pool - Pool identifier ('eth' or 'usdc', default: 'eth')
925
- * @param options.rpcUrl - Optional RPC URL
926
- * @returns Number of free deposits remaining today
927
- *
928
- * @example
929
- * ```typescript
930
- * const remaining = await getDailyFreeRemaining({
931
- * address: '0x...',
932
- * pool: 'eth',
933
- * });
934
- * console.log(`Free deposits left today: ${remaining}`);
935
- * ```
936
- */
937
- declare function getDailyFreeRemaining(options: {
938
- address: `0x${string}`;
939
- pool?: RelayPool;
940
- rpcUrl?: string;
941
- }): Promise<number>;
942
923
  /**
943
924
  * Get private balance from the Pool contract
944
925
  * Decrypts all encrypted outputs, calculates nullifiers, and checks spent status
@@ -1027,6 +1008,130 @@ declare function buildWithdrawProof(options: BuildWithdrawProofOptions): Promise
1027
1008
  */
1028
1009
  declare function withdraw(options: BuildWithdrawProofOptions): Promise<WithdrawResult>;
1029
1010
 
1011
+ interface PayX402ResourceOptions {
1012
+ url: string;
1013
+ rootPrivateKey: `0x${string}`;
1014
+ payerIndex: bigint | number | string;
1015
+ rpcUrl?: string;
1016
+ relayUrl?: string;
1017
+ /**
1018
+ * Maximum USDC the caller will pay for this resource, as a human-readable
1019
+ * decimal string (e.g. "0.10" or "10"). If the merchant's x402 requirement
1020
+ * exceeds this cap, the payment is rejected before any proof is built or the
1021
+ * payer EOA is funded. Prefer setting a tight per-request cap.
1022
+ */
1023
+ maxPayment?: string;
1024
+ fetchImpl?: typeof fetch;
1025
+ init?: RequestInit;
1026
+ provingKeyPath?: ProvingKeyPath;
1027
+ onProgress?: (stage: string, detail?: string) => void;
1028
+ /**
1029
+ * Fired immediately after the payer EOA is funded by the relay, before the
1030
+ * x402 payment is signed and submitted. Lets callers persist a funded-state
1031
+ * record so that funds are traceable even if a later step (signing, the second
1032
+ * fetch, settle-header parse) fails. Best-effort: callback errors are ignored.
1033
+ */
1034
+ onPayerFunded?: (info: X402PayerFundedInfo) => void;
1035
+ /**
1036
+ * Controls funding when the derived payer EOA already holds USDC:
1037
+ * - `true`: if the payer holds >= the required amount, skip the relay-funded
1038
+ * withdrawal and pay from that balance; throws if the balance is insufficient.
1039
+ * - `'topup'`: reuse the payer, withdrawing only the shortfall (amount - balance)
1040
+ * when it holds less than the price. Drains stranded dust toward zero without a
1041
+ * fresh full withdrawal; if the payer already holds enough, funding is skipped.
1042
+ * - `false`/undefined: always withdraw the full amount to the payer.
1043
+ * Use reuse to retry a payment whose funding succeeded but whose delivery failed.
1044
+ */
1045
+ reuseExistingBalance?: boolean | 'topup';
1046
+ }
1047
+ interface X402PayerFundedInfo {
1048
+ payerAddress: `0x${string}`;
1049
+ payerIndex: string;
1050
+ amount: string;
1051
+ amountAtomic: string;
1052
+ relayTransactionHash: string;
1053
+ relayBlockNumber: string;
1054
+ }
1055
+ interface PayX402ResourceResult {
1056
+ response: Response;
1057
+ payerAddress: `0x${string}`;
1058
+ payerIndex: string;
1059
+ amount: string;
1060
+ amountAtomic: string;
1061
+ relayTransactionHash: string;
1062
+ relayBlockNumber: string;
1063
+ paymentResponse?: SettleResponse;
1064
+ paymentTransactionHash?: string;
1065
+ }
1066
+ declare function usdcAtomicToDecimalString(amountAtomic: string | bigint): string;
1067
+ /**
1068
+ * Convert a human-readable USDC amount (e.g. "10" or "0.10") to atomic units.
1069
+ */
1070
+ declare function usdcDecimalToAtomic(amount: string): bigint;
1071
+ declare function deriveX402PayerKey(rootPrivateKey: string, index: bigint | number | string): `0x${string}`;
1072
+ declare function deriveX402PayerAddress(rootPrivateKey: string, index: bigint | number | string): `0x${string}`;
1073
+ declare function selectBaseUsdcExactRequirement(paymentRequired: PaymentRequired): PaymentRequirements;
1074
+ declare function payX402Resource(options: PayX402ResourceOptions): Promise<PayX402ResourceResult>;
1075
+ interface QuoteX402ResourceOptions {
1076
+ url: string;
1077
+ rpcUrl?: string;
1078
+ /**
1079
+ * Optional USDC spend cap (decimal string). When set, the result reports
1080
+ * whether the merchant's price exceeds it so a caller can refuse before paying.
1081
+ */
1082
+ maxPayment?: string;
1083
+ fetchImpl?: typeof fetch;
1084
+ init?: RequestInit;
1085
+ }
1086
+ interface QuoteX402ResourceResult {
1087
+ /** True when the endpoint returned HTTP 402 (payment required). */
1088
+ requiresPayment: boolean;
1089
+ /** True when the 402 offers a Veil-supported exact Base USDC requirement. */
1090
+ supported: boolean;
1091
+ /** Initial HTTP status from the unpaid probe. */
1092
+ status: number;
1093
+ amount?: string;
1094
+ amountAtomic?: string;
1095
+ payTo?: string;
1096
+ network?: string;
1097
+ asset?: string;
1098
+ /** Set when maxPayment was supplied: true if the price exceeds the cap. */
1099
+ exceedsMax?: boolean;
1100
+ maxPayment?: string;
1101
+ /** Parsed response body for a non-402 probe, so the caller can see the error. */
1102
+ body?: unknown;
1103
+ /** Populated when a 402 was returned but no supported requirement could be parsed. */
1104
+ error?: string;
1105
+ }
1106
+ /**
1107
+ * Probe an x402 resource WITHOUT funding a payer or signing a payment. Returns
1108
+ * the price/requirement for a supported 402, or the raw response for anything
1109
+ * else, so a caller can validate the request and confirm cost before committing
1110
+ * a withdrawal. Note: a merchant that only validates the request body after
1111
+ * payment will still return 402 here; this cannot catch post-payment errors.
1112
+ */
1113
+ declare function quoteX402Resource(options: QuoteX402ResourceOptions): Promise<QuoteX402ResourceResult>;
1114
+ interface X402PayerBalance {
1115
+ payerIndex: string;
1116
+ payerAddress: `0x${string}`;
1117
+ usdc: string;
1118
+ usdcAtomic: string;
1119
+ }
1120
+ interface GetX402PayerBalancesOptions {
1121
+ rootPrivateKey: `0x${string}`;
1122
+ startIndex?: bigint | number | string;
1123
+ count?: number;
1124
+ rpcUrl?: string;
1125
+ /** When true, only return payers that currently hold a non-zero USDC balance. */
1126
+ nonZeroOnly?: boolean;
1127
+ }
1128
+ /**
1129
+ * Inspect Base USDC balances held by deterministic x402 payer EOAs over an index
1130
+ * range. Useful for surfacing dust or funds left on a payer when a payment failed
1131
+ * after funding. This is read-only; it does not move funds or reuse payers.
1132
+ */
1133
+ declare function getX402PayerBalances(options: GetX402PayerBalancesOptions): Promise<X402PayerBalance[]>;
1134
+
1030
1135
  /**
1031
1136
  * Check if a recipient is registered and get their deposit key
1032
1137
  *
@@ -1710,18 +1815,6 @@ declare const QUEUE_ABI: readonly [{
1710
1815
  }];
1711
1816
  readonly stateMutability: "view";
1712
1817
  readonly type: "function";
1713
- }, {
1714
- readonly inputs: readonly [{
1715
- readonly name: "_depositor";
1716
- readonly type: "address";
1717
- }];
1718
- readonly name: "getDailyFreeRemaining";
1719
- readonly outputs: readonly [{
1720
- readonly name: "remaining";
1721
- readonly type: "uint256";
1722
- }];
1723
- readonly stateMutability: "view";
1724
- readonly type: "function";
1725
1818
  }];
1726
1819
  /**
1727
1820
  * ETH Pool Contract ABI
@@ -2854,4 +2947,4 @@ declare function getExtDataHash(extData: ExtDataInput): bigint;
2854
2947
  */
2855
2948
  declare function shuffle<T>(array: T[]): T[];
2856
2949
 
2857
- export { ADDRESSES, type BuildTransferProofOptions, type BuildWithdrawProofOptions, CIRCUIT_CONFIG, type DepositTxOptions, ENTRY_ABI, ERC20_ABI, type EncryptedMessage, type ExtData, type ExtDataInput, FIELD_SIZE, FORWARDER_ABI, FORWARDER_CONTRACT_VERSION, FORWARDER_FACTORY_ABI, Keypair, MAX_SUBACCOUNT_SLOTS, MERKLE_TREE_HEIGHT, type MessageSigner, type NetworkAddresses, POOL_ABI, POOL_CONFIG, type PendingDeposit, type PoolConfig, type PrepareTransactionParams, type PrivateBalanceResult, type ProgressCallback, type ProofArgs, type ProofBuildResult, type ProofInput, type ProveOptions, type ProvingKeyPath, QUEUE_ABI, type QueueBalanceResult, type RegisterTxOptions, RelayError, type RelayErrorResponse, type RelayExtData, type RelayMetadata, type RelayPool, type RelayProofArgs, type RelayRequest, type RelayResponse, type RelayType, type SubaccountAsset, type SubaccountAssetBalance, type SubaccountBalances, type SubaccountDeployRequest, type SubaccountMergeOptions, type SubaccountMergeResult, type SubaccountPrivateBalanceStatus, type SubaccountPrivateBalances, type SubaccountQueueStatus, type SubaccountRecoveryResult, type SubaccountRelayResult, type SubaccountSlot, type SubaccountStatusResult, type SubaccountSweepRequest, type SubaccountWithdrawTypedData, type SubmitRelayOptions, type Token, type TransactionData, type TransactionResult, type TransferResult, Utxo, type UtxoInfo, type UtxoParams, type UtxoSelectionResult, VEIL_SIGNED_MESSAGE, type WithdrawResult, buildApproveUSDCTx, buildChangeDepositKeyTx, buildDepositETHTx, buildDepositTx, buildDepositUSDCTx, buildMerkleTree, buildRegisterTx, buildSubaccountRecoveryTx, buildSubaccountWithdrawTypedData, buildTransferProof, buildWithdrawProof, checkRecipientRegistration, checkRelayHealth, deploySubaccountForwarder, deriveSubaccountChildDepositKey, deriveSubaccountChildOwner, deriveSubaccountChildPrivateKey, deriveSubaccountSalt, deriveSubaccountSlot, findNextSubaccountWithdrawNonce, getAddresses, getDailyFreeRemaining, getExtDataHash, getForwarderFactoryAddress, getMerklePath, getPoolAddress, getPrivateBalance, getQueueAddress, getQueueBalance, getRelayInfo, getRelayUrl, getSubaccountPrivateBalance, getSubaccountStatus, isSubaccountForwarderDeployed, isSubaccountWithdrawNonceUsed, mergeSubaccount, mergeUtxos, packEncryptedMessage, poseidonHash, poseidonHash2, predictSubaccountForwarder, prepareTransaction, prove, randomBN, selectCircuit, selectUtxosForWithdraw, shuffle, signSubaccountWithdraw, submitRelay, sweepSubaccountForwarder, toBuffer, toFixedHex, transfer, unpackEncryptedMessage, withdraw };
2950
+ export { ADDRESSES, type BuildTransferProofOptions, type BuildWithdrawProofOptions, CIRCUIT_CONFIG, type DepositTxOptions, ENTRY_ABI, ERC20_ABI, type EncryptedMessage, type ExtData, type ExtDataInput, FIELD_SIZE, FORWARDER_ABI, FORWARDER_CONTRACT_VERSION, FORWARDER_FACTORY_ABI, type GetX402PayerBalancesOptions, Keypair, MAX_SUBACCOUNT_SLOTS, MERKLE_TREE_HEIGHT, type MessageSigner, type NetworkAddresses, POOL_ABI, POOL_CONFIG, type PayX402ResourceOptions, type PayX402ResourceResult, type PendingDeposit, type PoolConfig, type PrepareTransactionParams, type PrivateBalanceResult, type ProgressCallback, type ProofArgs, type ProofBuildResult, type ProofInput, type ProveOptions, type ProvingKeyPath, QUEUE_ABI, type QueueBalanceResult, type QuoteX402ResourceOptions, type QuoteX402ResourceResult, type RegisterTxOptions, RelayError, type RelayErrorResponse, type RelayExtData, type RelayMetadata, type RelayPool, type RelayProofArgs, type RelayRequest, type RelayResponse, type RelayType, type SubaccountAsset, type SubaccountAssetBalance, type SubaccountBalances, type SubaccountDeployRequest, type SubaccountMergeOptions, type SubaccountMergeResult, type SubaccountPrivateBalanceStatus, type SubaccountPrivateBalances, type SubaccountQueueStatus, type SubaccountRecoveryResult, type SubaccountRelayResult, type SubaccountSlot, type SubaccountStatusResult, type SubaccountSweepRequest, type SubaccountWithdrawTypedData, type SubmitRelayOptions, type Token, type TransactionData, type TransactionResult, type TransferResult, Utxo, type UtxoInfo, type UtxoParams, type UtxoSelectionResult, VEIL_SIGNED_MESSAGE, type WithdrawResult, type X402PayerBalance, type X402PayerFundedInfo, buildApproveUSDCTx, buildChangeDepositKeyTx, buildDepositETHTx, buildDepositTx, buildDepositUSDCTx, buildMerkleTree, buildRegisterTx, buildSubaccountRecoveryTx, buildSubaccountWithdrawTypedData, buildTransferProof, buildWithdrawProof, checkRecipientRegistration, checkRelayHealth, deploySubaccountForwarder, deriveSubaccountChildDepositKey, deriveSubaccountChildOwner, deriveSubaccountChildPrivateKey, deriveSubaccountSalt, deriveSubaccountSlot, deriveX402PayerAddress, deriveX402PayerKey, findNextSubaccountWithdrawNonce, getAddresses, getExtDataHash, getForwarderFactoryAddress, getMerklePath, getPoolAddress, getPrivateBalance, getQueueAddress, getQueueBalance, getRelayInfo, getRelayUrl, getSubaccountPrivateBalance, getSubaccountStatus, getX402PayerBalances, isSubaccountForwarderDeployed, isSubaccountWithdrawNonceUsed, mergeSubaccount, mergeUtxos, packEncryptedMessage, payX402Resource, poseidonHash, poseidonHash2, predictSubaccountForwarder, prepareTransaction, prove, quoteX402Resource, randomBN, selectBaseUsdcExactRequirement, selectCircuit, selectUtxosForWithdraw, shuffle, signSubaccountWithdraw, submitRelay, sweepSubaccountForwarder, toBuffer, toFixedHex, transfer, unpackEncryptedMessage, usdcAtomicToDecimalString, usdcDecimalToAtomic, withdraw };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { Buffer } from 'buffer';
2
+ import { SettleResponse, PaymentRequired, PaymentRequirements } from '@x402/core/types';
2
3
  import MerkleTree from 'fixed-merkle-tree-legacy';
3
4
 
4
5
  /**
@@ -285,9 +286,12 @@ interface RelayExtData {
285
286
  */
286
287
  interface RelayMetadata {
287
288
  amount?: string;
289
+ amountAtomic?: string;
288
290
  recipient?: string;
289
291
  inputUtxoCount?: number;
290
292
  outputUtxoCount?: number;
293
+ x402?: boolean;
294
+ payerIndex?: string;
291
295
  }
292
296
  /**
293
297
  * Request body for relay service
@@ -349,6 +353,8 @@ interface BuildWithdrawProofOptions {
349
353
  pool?: RelayPool;
350
354
  /** Optional RPC URL */
351
355
  rpcUrl?: string;
356
+ /** Optional relay URL */
357
+ relayUrl?: string;
352
358
  /**
353
359
  * Optional proving key directory/base URL or resolver.
354
360
  *
@@ -914,31 +920,6 @@ declare function getQueueBalance(options: {
914
920
  rpcUrl?: string;
915
921
  onProgress?: ProgressCallback;
916
922
  }): Promise<QueueBalanceResult>;
917
- /**
918
- * Get remaining daily free deposits for an address.
919
- * Returns 0 if the queue contract has not been upgraded to V3 yet
920
- * or if the daily free feature is disabled.
921
- *
922
- * @param options - Query options
923
- * @param options.address - Depositor address to check
924
- * @param options.pool - Pool identifier ('eth' or 'usdc', default: 'eth')
925
- * @param options.rpcUrl - Optional RPC URL
926
- * @returns Number of free deposits remaining today
927
- *
928
- * @example
929
- * ```typescript
930
- * const remaining = await getDailyFreeRemaining({
931
- * address: '0x...',
932
- * pool: 'eth',
933
- * });
934
- * console.log(`Free deposits left today: ${remaining}`);
935
- * ```
936
- */
937
- declare function getDailyFreeRemaining(options: {
938
- address: `0x${string}`;
939
- pool?: RelayPool;
940
- rpcUrl?: string;
941
- }): Promise<number>;
942
923
  /**
943
924
  * Get private balance from the Pool contract
944
925
  * Decrypts all encrypted outputs, calculates nullifiers, and checks spent status
@@ -1027,6 +1008,130 @@ declare function buildWithdrawProof(options: BuildWithdrawProofOptions): Promise
1027
1008
  */
1028
1009
  declare function withdraw(options: BuildWithdrawProofOptions): Promise<WithdrawResult>;
1029
1010
 
1011
+ interface PayX402ResourceOptions {
1012
+ url: string;
1013
+ rootPrivateKey: `0x${string}`;
1014
+ payerIndex: bigint | number | string;
1015
+ rpcUrl?: string;
1016
+ relayUrl?: string;
1017
+ /**
1018
+ * Maximum USDC the caller will pay for this resource, as a human-readable
1019
+ * decimal string (e.g. "0.10" or "10"). If the merchant's x402 requirement
1020
+ * exceeds this cap, the payment is rejected before any proof is built or the
1021
+ * payer EOA is funded. Prefer setting a tight per-request cap.
1022
+ */
1023
+ maxPayment?: string;
1024
+ fetchImpl?: typeof fetch;
1025
+ init?: RequestInit;
1026
+ provingKeyPath?: ProvingKeyPath;
1027
+ onProgress?: (stage: string, detail?: string) => void;
1028
+ /**
1029
+ * Fired immediately after the payer EOA is funded by the relay, before the
1030
+ * x402 payment is signed and submitted. Lets callers persist a funded-state
1031
+ * record so that funds are traceable even if a later step (signing, the second
1032
+ * fetch, settle-header parse) fails. Best-effort: callback errors are ignored.
1033
+ */
1034
+ onPayerFunded?: (info: X402PayerFundedInfo) => void;
1035
+ /**
1036
+ * Controls funding when the derived payer EOA already holds USDC:
1037
+ * - `true`: if the payer holds >= the required amount, skip the relay-funded
1038
+ * withdrawal and pay from that balance; throws if the balance is insufficient.
1039
+ * - `'topup'`: reuse the payer, withdrawing only the shortfall (amount - balance)
1040
+ * when it holds less than the price. Drains stranded dust toward zero without a
1041
+ * fresh full withdrawal; if the payer already holds enough, funding is skipped.
1042
+ * - `false`/undefined: always withdraw the full amount to the payer.
1043
+ * Use reuse to retry a payment whose funding succeeded but whose delivery failed.
1044
+ */
1045
+ reuseExistingBalance?: boolean | 'topup';
1046
+ }
1047
+ interface X402PayerFundedInfo {
1048
+ payerAddress: `0x${string}`;
1049
+ payerIndex: string;
1050
+ amount: string;
1051
+ amountAtomic: string;
1052
+ relayTransactionHash: string;
1053
+ relayBlockNumber: string;
1054
+ }
1055
+ interface PayX402ResourceResult {
1056
+ response: Response;
1057
+ payerAddress: `0x${string}`;
1058
+ payerIndex: string;
1059
+ amount: string;
1060
+ amountAtomic: string;
1061
+ relayTransactionHash: string;
1062
+ relayBlockNumber: string;
1063
+ paymentResponse?: SettleResponse;
1064
+ paymentTransactionHash?: string;
1065
+ }
1066
+ declare function usdcAtomicToDecimalString(amountAtomic: string | bigint): string;
1067
+ /**
1068
+ * Convert a human-readable USDC amount (e.g. "10" or "0.10") to atomic units.
1069
+ */
1070
+ declare function usdcDecimalToAtomic(amount: string): bigint;
1071
+ declare function deriveX402PayerKey(rootPrivateKey: string, index: bigint | number | string): `0x${string}`;
1072
+ declare function deriveX402PayerAddress(rootPrivateKey: string, index: bigint | number | string): `0x${string}`;
1073
+ declare function selectBaseUsdcExactRequirement(paymentRequired: PaymentRequired): PaymentRequirements;
1074
+ declare function payX402Resource(options: PayX402ResourceOptions): Promise<PayX402ResourceResult>;
1075
+ interface QuoteX402ResourceOptions {
1076
+ url: string;
1077
+ rpcUrl?: string;
1078
+ /**
1079
+ * Optional USDC spend cap (decimal string). When set, the result reports
1080
+ * whether the merchant's price exceeds it so a caller can refuse before paying.
1081
+ */
1082
+ maxPayment?: string;
1083
+ fetchImpl?: typeof fetch;
1084
+ init?: RequestInit;
1085
+ }
1086
+ interface QuoteX402ResourceResult {
1087
+ /** True when the endpoint returned HTTP 402 (payment required). */
1088
+ requiresPayment: boolean;
1089
+ /** True when the 402 offers a Veil-supported exact Base USDC requirement. */
1090
+ supported: boolean;
1091
+ /** Initial HTTP status from the unpaid probe. */
1092
+ status: number;
1093
+ amount?: string;
1094
+ amountAtomic?: string;
1095
+ payTo?: string;
1096
+ network?: string;
1097
+ asset?: string;
1098
+ /** Set when maxPayment was supplied: true if the price exceeds the cap. */
1099
+ exceedsMax?: boolean;
1100
+ maxPayment?: string;
1101
+ /** Parsed response body for a non-402 probe, so the caller can see the error. */
1102
+ body?: unknown;
1103
+ /** Populated when a 402 was returned but no supported requirement could be parsed. */
1104
+ error?: string;
1105
+ }
1106
+ /**
1107
+ * Probe an x402 resource WITHOUT funding a payer or signing a payment. Returns
1108
+ * the price/requirement for a supported 402, or the raw response for anything
1109
+ * else, so a caller can validate the request and confirm cost before committing
1110
+ * a withdrawal. Note: a merchant that only validates the request body after
1111
+ * payment will still return 402 here; this cannot catch post-payment errors.
1112
+ */
1113
+ declare function quoteX402Resource(options: QuoteX402ResourceOptions): Promise<QuoteX402ResourceResult>;
1114
+ interface X402PayerBalance {
1115
+ payerIndex: string;
1116
+ payerAddress: `0x${string}`;
1117
+ usdc: string;
1118
+ usdcAtomic: string;
1119
+ }
1120
+ interface GetX402PayerBalancesOptions {
1121
+ rootPrivateKey: `0x${string}`;
1122
+ startIndex?: bigint | number | string;
1123
+ count?: number;
1124
+ rpcUrl?: string;
1125
+ /** When true, only return payers that currently hold a non-zero USDC balance. */
1126
+ nonZeroOnly?: boolean;
1127
+ }
1128
+ /**
1129
+ * Inspect Base USDC balances held by deterministic x402 payer EOAs over an index
1130
+ * range. Useful for surfacing dust or funds left on a payer when a payment failed
1131
+ * after funding. This is read-only; it does not move funds or reuse payers.
1132
+ */
1133
+ declare function getX402PayerBalances(options: GetX402PayerBalancesOptions): Promise<X402PayerBalance[]>;
1134
+
1030
1135
  /**
1031
1136
  * Check if a recipient is registered and get their deposit key
1032
1137
  *
@@ -1710,18 +1815,6 @@ declare const QUEUE_ABI: readonly [{
1710
1815
  }];
1711
1816
  readonly stateMutability: "view";
1712
1817
  readonly type: "function";
1713
- }, {
1714
- readonly inputs: readonly [{
1715
- readonly name: "_depositor";
1716
- readonly type: "address";
1717
- }];
1718
- readonly name: "getDailyFreeRemaining";
1719
- readonly outputs: readonly [{
1720
- readonly name: "remaining";
1721
- readonly type: "uint256";
1722
- }];
1723
- readonly stateMutability: "view";
1724
- readonly type: "function";
1725
1818
  }];
1726
1819
  /**
1727
1820
  * ETH Pool Contract ABI
@@ -2854,4 +2947,4 @@ declare function getExtDataHash(extData: ExtDataInput): bigint;
2854
2947
  */
2855
2948
  declare function shuffle<T>(array: T[]): T[];
2856
2949
 
2857
- export { ADDRESSES, type BuildTransferProofOptions, type BuildWithdrawProofOptions, CIRCUIT_CONFIG, type DepositTxOptions, ENTRY_ABI, ERC20_ABI, type EncryptedMessage, type ExtData, type ExtDataInput, FIELD_SIZE, FORWARDER_ABI, FORWARDER_CONTRACT_VERSION, FORWARDER_FACTORY_ABI, Keypair, MAX_SUBACCOUNT_SLOTS, MERKLE_TREE_HEIGHT, type MessageSigner, type NetworkAddresses, POOL_ABI, POOL_CONFIG, type PendingDeposit, type PoolConfig, type PrepareTransactionParams, type PrivateBalanceResult, type ProgressCallback, type ProofArgs, type ProofBuildResult, type ProofInput, type ProveOptions, type ProvingKeyPath, QUEUE_ABI, type QueueBalanceResult, type RegisterTxOptions, RelayError, type RelayErrorResponse, type RelayExtData, type RelayMetadata, type RelayPool, type RelayProofArgs, type RelayRequest, type RelayResponse, type RelayType, type SubaccountAsset, type SubaccountAssetBalance, type SubaccountBalances, type SubaccountDeployRequest, type SubaccountMergeOptions, type SubaccountMergeResult, type SubaccountPrivateBalanceStatus, type SubaccountPrivateBalances, type SubaccountQueueStatus, type SubaccountRecoveryResult, type SubaccountRelayResult, type SubaccountSlot, type SubaccountStatusResult, type SubaccountSweepRequest, type SubaccountWithdrawTypedData, type SubmitRelayOptions, type Token, type TransactionData, type TransactionResult, type TransferResult, Utxo, type UtxoInfo, type UtxoParams, type UtxoSelectionResult, VEIL_SIGNED_MESSAGE, type WithdrawResult, buildApproveUSDCTx, buildChangeDepositKeyTx, buildDepositETHTx, buildDepositTx, buildDepositUSDCTx, buildMerkleTree, buildRegisterTx, buildSubaccountRecoveryTx, buildSubaccountWithdrawTypedData, buildTransferProof, buildWithdrawProof, checkRecipientRegistration, checkRelayHealth, deploySubaccountForwarder, deriveSubaccountChildDepositKey, deriveSubaccountChildOwner, deriveSubaccountChildPrivateKey, deriveSubaccountSalt, deriveSubaccountSlot, findNextSubaccountWithdrawNonce, getAddresses, getDailyFreeRemaining, getExtDataHash, getForwarderFactoryAddress, getMerklePath, getPoolAddress, getPrivateBalance, getQueueAddress, getQueueBalance, getRelayInfo, getRelayUrl, getSubaccountPrivateBalance, getSubaccountStatus, isSubaccountForwarderDeployed, isSubaccountWithdrawNonceUsed, mergeSubaccount, mergeUtxos, packEncryptedMessage, poseidonHash, poseidonHash2, predictSubaccountForwarder, prepareTransaction, prove, randomBN, selectCircuit, selectUtxosForWithdraw, shuffle, signSubaccountWithdraw, submitRelay, sweepSubaccountForwarder, toBuffer, toFixedHex, transfer, unpackEncryptedMessage, withdraw };
2950
+ export { ADDRESSES, type BuildTransferProofOptions, type BuildWithdrawProofOptions, CIRCUIT_CONFIG, type DepositTxOptions, ENTRY_ABI, ERC20_ABI, type EncryptedMessage, type ExtData, type ExtDataInput, FIELD_SIZE, FORWARDER_ABI, FORWARDER_CONTRACT_VERSION, FORWARDER_FACTORY_ABI, type GetX402PayerBalancesOptions, Keypair, MAX_SUBACCOUNT_SLOTS, MERKLE_TREE_HEIGHT, type MessageSigner, type NetworkAddresses, POOL_ABI, POOL_CONFIG, type PayX402ResourceOptions, type PayX402ResourceResult, type PendingDeposit, type PoolConfig, type PrepareTransactionParams, type PrivateBalanceResult, type ProgressCallback, type ProofArgs, type ProofBuildResult, type ProofInput, type ProveOptions, type ProvingKeyPath, QUEUE_ABI, type QueueBalanceResult, type QuoteX402ResourceOptions, type QuoteX402ResourceResult, type RegisterTxOptions, RelayError, type RelayErrorResponse, type RelayExtData, type RelayMetadata, type RelayPool, type RelayProofArgs, type RelayRequest, type RelayResponse, type RelayType, type SubaccountAsset, type SubaccountAssetBalance, type SubaccountBalances, type SubaccountDeployRequest, type SubaccountMergeOptions, type SubaccountMergeResult, type SubaccountPrivateBalanceStatus, type SubaccountPrivateBalances, type SubaccountQueueStatus, type SubaccountRecoveryResult, type SubaccountRelayResult, type SubaccountSlot, type SubaccountStatusResult, type SubaccountSweepRequest, type SubaccountWithdrawTypedData, type SubmitRelayOptions, type Token, type TransactionData, type TransactionResult, type TransferResult, Utxo, type UtxoInfo, type UtxoParams, type UtxoSelectionResult, VEIL_SIGNED_MESSAGE, type WithdrawResult, type X402PayerBalance, type X402PayerFundedInfo, buildApproveUSDCTx, buildChangeDepositKeyTx, buildDepositETHTx, buildDepositTx, buildDepositUSDCTx, buildMerkleTree, buildRegisterTx, buildSubaccountRecoveryTx, buildSubaccountWithdrawTypedData, buildTransferProof, buildWithdrawProof, checkRecipientRegistration, checkRelayHealth, deploySubaccountForwarder, deriveSubaccountChildDepositKey, deriveSubaccountChildOwner, deriveSubaccountChildPrivateKey, deriveSubaccountSalt, deriveSubaccountSlot, deriveX402PayerAddress, deriveX402PayerKey, findNextSubaccountWithdrawNonce, getAddresses, getExtDataHash, getForwarderFactoryAddress, getMerklePath, getPoolAddress, getPrivateBalance, getQueueAddress, getQueueBalance, getRelayInfo, getRelayUrl, getSubaccountPrivateBalance, getSubaccountStatus, getX402PayerBalances, isSubaccountForwarderDeployed, isSubaccountWithdrawNonceUsed, mergeSubaccount, mergeUtxos, packEncryptedMessage, payX402Resource, poseidonHash, poseidonHash2, predictSubaccountForwarder, prepareTransaction, prove, quoteX402Resource, randomBN, selectBaseUsdcExactRequirement, selectCircuit, selectUtxosForWithdraw, shuffle, signSubaccountWithdraw, submitRelay, sweepSubaccountForwarder, toBuffer, toFixedHex, transfer, unpackEncryptedMessage, usdcAtomicToDecimalString, usdcDecimalToAtomic, withdraw };