import { Connection } from '@solana/web3.js'; /** * Crossmint smart wallet integration for RelAI x402. * * Two modes: * * **API-key mode** — zero private keys, Crossmint signs + broadcasts: * ```ts * import { createCrossmintX402Fetch } from "@relai-fi/x402/crossmint"; * * const fetch402 = createCrossmintX402Fetch({ * apiKey: process.env.CROSSMINT_API_KEY!, * wallet: process.env.CROSSMINT_WALLET!, * connection: new Connection(process.env.RPC_URL!), * }); * const resp = await fetch402("https://api.example.com/protected"); * ``` * * **Delegated mode** — external signer approves each transaction: * ```ts * import { createCrossmintDelegatedX402Fetch } from "@relai-fi/x402/crossmint"; * * const fetch402 = createCrossmintDelegatedX402Fetch({ * apiKey: process.env.CROSSMINT_API_KEY!, * wallet: process.env.CROSSMINT_WALLET!, * signerSecretKey: myKeypairBytes, // 64-byte Ed25519 * connection: new Connection(process.env.RPC_URL!), * }); * const resp = await fetch402("https://api.example.com/protected"); * ``` * * @module */ interface CrossmintX402Config { /** Crossmint server-side API key (`sk_production_...` or `sk_staging_...`) */ apiKey: string; /** Crossmint smart wallet address (Solana public key) */ wallet: string; /** Solana RPC connection */ connection: Connection; /** Override Crossmint API base URL (default: `https://www.crossmint.com/api/2025-06-09`) */ crossmintApiBase?: string; /** Max polling attempts for tx confirmation (default: 30) */ maxPollAttempts?: number; /** Polling interval in ms (default: 2000) */ pollIntervalMs?: number; /** Called after successful on-chain payment with the Solana tx signature */ onPayment?: (txHash: string) => void; } interface CrossmintDelegatedX402Config extends CrossmintX402Config { /** * Ed25519 secret key for the external signer (64 bytes). * The corresponding public key must be registered as an external signer * on the Crossmint smart wallet. */ signerSecretKey: Uint8Array; /** Crossmint environment: "staging" or "production" (default: auto-detect from apiKey) */ environment?: "staging" | "production"; } /** * **API-key mode.** Create a fetch wrapper that auto-handles x402 `402` * responses using a Crossmint smart wallet on Solana. * * Crossmint signs and broadcasts — no private key needed. * The returned function has the same signature as `fetch()`. */ declare function createCrossmintX402Fetch(config: CrossmintX402Config): (url: string, init?: RequestInit) => Promise; /** * **Delegated mode.** Create a fetch wrapper that auto-handles x402 `402` * responses using a Crossmint smart wallet with external signer approval. * * Each transaction requires cryptographic approval from `signerSecretKey` * before Crossmint broadcasts. This provides an extra security layer — * even with the API key, transactions cannot execute without the signer. * * The external signer must be registered on the Crossmint smart wallet * via the Crossmint console or API. */ declare function createCrossmintDelegatedX402Fetch(config: CrossmintDelegatedX402Config): (url: string, init?: RequestInit) => Promise; export { type CrossmintDelegatedX402Config, type CrossmintX402Config, createCrossmintDelegatedX402Fetch, createCrossmintX402Fetch };