export { E as ExactSvmScheme } from './scheme-fjF-9LhT.mjs'; export { a as ClientSvmConfig, C as ClientSvmSigner, c as FacilitatorRpcClient, d as FacilitatorRpcConfig, F as FacilitatorSvmSigner, t as toClientSvmSigner, b as toFacilitatorSvmSigner } from './signer-BMkbhFYE.mjs'; export { S as SettlementCache } from './settlement-cache-D9gb94wH.mjs'; import { Transaction, RpcDevnet, SolanaRpcApiDevnet, RpcTestnet, SolanaRpcApiTestnet, RpcMainnet, SolanaRpcApiMainnet, Instruction, Address } from '@solana/kit'; import { Network } from '@payai/x402/types'; export { convertToTokenAmount, numberToDecimalString } from '@payai/x402/utils'; /** * Exact SVM payload structure containing a base64 encoded Solana transaction */ type ExactSvmPayloadV1 = { /** * Base64 encoded Solana transaction */ transaction: string; }; /** * Exact SVM payload V2 structure (currently same as V1, reserved for future extensions) */ type ExactSvmPayloadV2 = ExactSvmPayloadV1; /** * Token program addresses for SPL Token and Token-2022 * These addresses are the same across all Solana networks (mainnet, devnet, testnet) */ declare const TOKEN_PROGRAM_ADDRESS = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"; declare const TOKEN_2022_PROGRAM_ADDRESS = "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"; declare const COMPUTE_BUDGET_PROGRAM_ADDRESS = "ComputeBudget111111111111111111111111111111"; declare const MEMO_PROGRAM_ADDRESS = "MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"; /** * Swig smart wallet program address and instruction discriminators. * Swig wraps inner instructions (e.g. SPL transferChecked) inside a SignV2 * instruction and executes them via CPI using the Swig PDA as authority. * See: https://github.com/anagram-xyz/swig */ declare const SWIG_PROGRAM_ADDRESS = "swigypWHEksbC64pWKwah1WTeh9JXwx8H1rJHLdbQMB"; declare const SWIG_SIGN_V2_DISCRIMINATOR = 11; /** * Secp256r1 precompile program address (used by Swig passkey wallets) * Swig transactions may include secp256r1 signature verification instructions * before the SignV2 instruction. These are filtered out during transaction flattening. */ declare const SECP256R1_PRECOMPILE_ADDRESS = "Secp256r1SigVerify1111111111111111111111111"; /** * Phantom/Solflare Lighthouse program address * Phantom and Solflare wallets inject Lighthouse instructions for user protection on mainnet transactions. * - Phantom adds 1 Lighthouse instruction (4th instruction) * - Solflare adds 2 Lighthouse instructions (4th and 5th instructions) * We allow these as optional instructions to support these wallets. * See: https://github.com/x402-foundation/x402/issues/828 */ declare const LIGHTHOUSE_PROGRAM_ADDRESS = "L2TExMFKdjpN9kozasaurPirfHy9P8sbXoAN1qA3S95"; /** * Default RPC URLs for Solana networks */ declare const DEVNET_RPC_URL = "https://api.devnet.solana.com"; declare const TESTNET_RPC_URL = "https://api.testnet.solana.com"; declare const MAINNET_RPC_URL = "https://api.mainnet-beta.solana.com"; declare const DEVNET_WS_URL = "wss://api.devnet.solana.com"; declare const TESTNET_WS_URL = "wss://api.testnet.solana.com"; declare const MAINNET_WS_URL = "wss://api.mainnet-beta.solana.com"; /** * USDC token mint addresses (default stablecoin) */ declare const USDC_MAINNET_ADDRESS = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"; declare const USDC_DEVNET_ADDRESS = "4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU"; declare const USDC_TESTNET_ADDRESS = "4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU"; /** * Compute budget configuration * All prices are in microlamports (1 lamport = 1,000,000 microlamports) */ declare const DEFAULT_COMPUTE_UNIT_PRICE_MICROLAMPORTS = 1; declare const DEFAULT_COMPUTE_UNIT_LIMIT = 20000; declare const MAX_MEMO_BYTES = 256; /** * Security limits to prevent fee amplification / DoS attacks. * These limits protect the facilitator from malicious payloads that attempt * to inflate gas costs while the facilitator pays fees. */ /** * Maximum compute unit price in microlamports. * Kept intentionally low to prevent bots from inflating priority fees * at the facilitator's expense (the facilitator pays gas). * Default: 5 microlamports. Override via MAX_SVM_COMPUTE_UNIT_PRICE_MICROLAMPORTS environment variable. */ declare const MAX_COMPUTE_UNIT_PRICE_MICROLAMPORTS: number; /** * Maximum compute unit limit. * SPL token transfer with memo uses ~20k CU. 60k provides 3x safety margin. * Wallets like Solflare add ~40k CU buffer, so we need headroom. * Prevents attackers from inflating CU budget at facilitator's expense. * Override via MAX_SVM_COMPUTE_UNIT_LIMIT environment variable. */ declare const MAX_COMPUTE_UNIT_LIMIT: number; /** * Maximum allowed required signatures. * Typical x402 flow: payer + fee payer = 2 signatures. * Higher values indicate multi-sig spam attempts. */ declare const MAX_REQUIRED_SIGNATURES = 2; /** * How long a transaction is held in the duplicate settlement cache (ms). * Covers the Solana blockhash lifetime (~60-90s) with margin. */ declare const SETTLEMENT_TTL_MS = 120000; /** * Solana address validation regex (base58, 32-44 characters) */ declare const SVM_ADDRESS_REGEX: RegExp; /** * CAIP-2 network identifiers for Solana (V2) */ declare const SOLANA_MAINNET_CAIP2 = "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp"; declare const SOLANA_DEVNET_CAIP2 = "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1"; declare const SOLANA_TESTNET_CAIP2 = "solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z"; /** * V1 to V2 network identifier mappings (for backwards compatibility) * V1 used simple names like solana, V2 uses CAIP-2 */ declare const V1_TO_V2_NETWORK_MAP: Record; /** * Normalize network identifier to CAIP-2 format * Handles both V1 names (solana, solana-devnet) and V2 CAIP-2 format * * @param network - Network identifier (V1 or V2 format) * @returns CAIP-2 network identifier */ declare function normalizeNetwork(network: Network): string; /** * Validate Solana address format * * @param address - Base58 encoded address string * @returns true if address is valid, false otherwise */ declare function validateSvmAddress(address: string): boolean; /** * Compute a stable, immutable cache key for a decoded transaction by hashing its * message bytes. The fee-payer signature (slot 0) is overwritten by the facilitator * before broadcast, so an attacker can randomize those bytes to bypass a wire-bytes * cache key. The message is what every signer commits to, making its hash a reliable * payment identity. * * @param transaction - Decoded transaction whose message bytes to hash * @returns Base64-encoded SHA-256 hash of the transaction message bytes */ declare function transactionMessageHash(transaction: Transaction): string; /** * Decode a base64 encoded transaction from an SVM payload * * @param svmPayload - The SVM payload containing a base64 encoded transaction * @returns Decoded Transaction object */ declare function decodeTransactionFromPayload(svmPayload: ExactSvmPayloadV1): Transaction; /** * Extract the token sender (owner of the source token account) from a TransferChecked instruction * * @param transaction - The decoded transaction * @returns The token payer address as a base58 string */ declare function getTokenPayerFromTransaction(transaction: Transaction): string; /** * Create an RPC client for the specified network * * @param network - Network identifier (CAIP-2 or V1 format) * @param customRpcUrl - Optional custom RPC URL * @returns RPC client for the specified network */ declare function createRpcClient(network: Network, customRpcUrl?: string): RpcDevnet | RpcTestnet | RpcMainnet; /** * Get the default USDC mint address for a network * * @param network - Network identifier (CAIP-2 or V1 format) * @returns USDC mint address for the network */ declare function getUsdcAddress(network: Network): string; /** * A decoded compact instruction extracted from a Swig SignV2 payload. * Indices reference the SignV2 instruction's own account list, not the outer * transaction's static account keys. */ interface SwigCompactInstruction { programIdIndex: number; accounts: number[]; data: Uint8Array; } /** * Returns true when the transaction has a Swig layout: * - Every instruction is one of: compute budget, secp256r1 precompile, or Swig SignV2 * - At least one Swig SignV2 instruction is present * * @param instructions - Decompiled instruction array * @returns True when the instruction list matches the Swig transaction shape. */ declare function isSwigTransaction(instructions: ReadonlyArray): boolean; /** * Flatten a Swig transaction into the same instruction layout as a regular one. * Collects non-precompile, non-SignV2 outer instructions (compute budgets) and * resolves the compact instructions embedded in each SignV2 instruction. * * A transaction may contain multiple SignV2 instructions. All must reference * the same Swig PDA (accounts[0]). * * @param instructions - Decompiled instruction array (from a Swig transaction) * @param _ - Ordered account list from the compiled transaction message. Swig parsing * currently resolves accounts from the SignV2 instruction payload instead. * @returns Object with flattened `instructions` array and `swigPda` address */ declare function parseSwigTransaction(instructions: ReadonlyArray, _: ReadonlyArray
): Promise<{ instructions: Array<{ programAddress: Address; accounts: Array<{ address: Address; role: number; }>; data: Uint8Array; }>; swigPda: string; }>; /** * Decode the compact instructions embedded inside a Swig SignV2 instruction. * * Layout of the outer instruction data: * [0..1] discriminator U16 LE * [2..3] instructionPayloadLen U16 LE (byte count of compact instructions) * [4..7] roleId U32 LE * [8..] compact instructions (instructionPayloadLen bytes) * * Compact instructions payload: * [0] numInstructions U8 * [1..] compact instruction entries... * * Each CompactInstruction: * [0] programIdIndex U8 * [1] numAccounts U8 * [2..N+1] accounts U8[numAccounts] * [N+2..N+3] dataLen U16 LE * [N+4..] data raw bytes * * @param data - The full instruction data bytes of the outer Swig instruction * @returns Array of decoded compact instructions (may be empty if data is malformed) */ declare function decodeSwigCompactInstructions(data: Uint8Array): SwigCompactInstruction[]; interface NormalizedTransaction { instructions: Array<{ programAddress: Address; accounts: Array<{ address: Address; role: number; }>; data: Uint8Array; }>; payer: string; } /** * Normalizes different SVM transaction shapes into a single facilitator-friendly * instruction list plus the effective payer that should be used for settlement. */ interface TransactionNormalizer { /** * Returns true when this normalizer understands the provided instruction layout. * * @param instructions - Decompiled instruction list from the transaction. * @returns True when the implementation can normalize the transaction. */ canHandle(instructions: ReadonlyArray): boolean; /** * Converts a transaction into the canonical shape expected by facilitator verification. * * @param instructions - Decompiled instruction list from the transaction. * @param staticAccounts - Ordered static account list from the compiled message. * @param transaction - Original decoded transaction. * @returns The normalized instruction set and payer. */ normalize(instructions: ReadonlyArray, staticAccounts: ReadonlyArray
, transaction: Transaction): Promise; } /** * Chooses the first matching normalizer and converts the transaction into the * canonical instruction shape consumed by the facilitator verifier. * * @param instructions - Decompiled instruction list from the transaction. * @param staticAccounts - Ordered static account list from the compiled message. * @param transaction - Original decoded transaction. * @returns The normalized instruction list and payer. */ declare function normalizeTransaction(instructions: ReadonlyArray, staticAccounts: ReadonlyArray
, transaction: Transaction): Promise; export { COMPUTE_BUDGET_PROGRAM_ADDRESS, DEFAULT_COMPUTE_UNIT_LIMIT, DEFAULT_COMPUTE_UNIT_PRICE_MICROLAMPORTS, DEVNET_RPC_URL, DEVNET_WS_URL, type ExactSvmPayloadV1, type ExactSvmPayloadV2, LIGHTHOUSE_PROGRAM_ADDRESS, MAINNET_RPC_URL, MAINNET_WS_URL, MAX_COMPUTE_UNIT_LIMIT, MAX_COMPUTE_UNIT_PRICE_MICROLAMPORTS, MAX_MEMO_BYTES, MAX_REQUIRED_SIGNATURES, MEMO_PROGRAM_ADDRESS, type NormalizedTransaction, SECP256R1_PRECOMPILE_ADDRESS, SETTLEMENT_TTL_MS, SOLANA_DEVNET_CAIP2, SOLANA_MAINNET_CAIP2, SOLANA_TESTNET_CAIP2, SVM_ADDRESS_REGEX, SWIG_PROGRAM_ADDRESS, SWIG_SIGN_V2_DISCRIMINATOR, type SwigCompactInstruction, TESTNET_RPC_URL, TESTNET_WS_URL, TOKEN_2022_PROGRAM_ADDRESS, TOKEN_PROGRAM_ADDRESS, type TransactionNormalizer, USDC_DEVNET_ADDRESS, USDC_MAINNET_ADDRESS, USDC_TESTNET_ADDRESS, V1_TO_V2_NETWORK_MAP, createRpcClient, decodeSwigCompactInstructions, decodeTransactionFromPayload, getTokenPayerFromTransaction, getUsdcAddress, isSwigTransaction, normalizeNetwork, normalizeTransaction, parseSwigTransaction, transactionMessageHash, validateSvmAddress };