/** * Global window interface extension for Spark wallet providers */ declare global { interface IWindowSpark { SparkProvider: ISparkProvider; } interface Window { magicEden?: { spark: ISparkProvider; }; } } /** * Interface that all Spark wallet providers must implement. * * This interface defines the contract that any Spark wallet provider must fulfill * to be compatible with the Dynamic SDK. It includes core functionality for * connection, authentication, and transactions. * * ## Design Philosophy * This interface is designed to be **flexible and extensible** while maintaining * a consistent contract. Different wallet implementations can use different * naming conventions and return formats without breaking compatibility. * * ## Flexibility Features * - **Dual Naming Support**: Supports both `sparkAddress`/`address` naming conventions * - **Flexible Return Types**: Methods can return different formats (objects, strings, etc.) * - **Optional Parameters**: Advanced features like `isTaproot` are optional with sensible defaults * - **Extensible**: Additional properties are allowed via `[key: string]: unknown` * * ## Usage Examples * ```typescript * // Magic Eden style (sparkAddress naming) * const result = await provider.connect(); * // result can be: string | { sparkAddress: string, sparkTaprootAddress?: string } * * // Generic style (address naming) * const address = await provider.getAddress(); * // address can be: string | { address: string, taprootAddress?: string } * * // Simple message signing * const signature = await provider.signMessage("Hello World"); * // Advanced signing with Taproot * const signature = await provider.signMessage({ message: "Hello", isTaproot: true }); * ``` */ export interface ISparkProvider { /** Whether the wallet is currently connected */ isConnected: boolean; /** The current network chain ID (e.g., '301' for mainnet) */ chainId?: string; /** The current network name (e.g., 'mainnet', 'testnet') */ network?: string; /** * Establishes a connection to the wallet * @returns Promise resolving to connection result with address information */ connect(): Promise; /** * Disconnects from the wallet * @returns Promise that resolves when disconnected */ disconnect(): Promise; /** * Retrieves the current wallet address * @returns Promise resolving to address information */ getAddress(): Promise; /** * Signs a message for authentication * @param message - Message to sign or signing request object * @returns Promise resolving to signature result */ signMessage(message: string | SparkSignMessageRequest): Promise; /** * Signs a message using Taproot protocol * @param message - Message to sign * @returns Promise resolving to signature result */ signMessageWithTaproot(message: string): Promise; /** * Transfers Bitcoin to another Spark address * @param params - Transfer parameters * @param params.receiverSparkAddress - The recipient's Spark address * @param params.amountSats - Amount to transfer in satoshis * @param params.isTaproot - Whether to use Taproot (defaults to false) * @returns Promise resolving to transaction hash */ transferBitcoin(params: { receiverSparkAddress: string; amountSats: string | number; isTaproot?: boolean; }): Promise; /** * Transfers tokens to another Spark address * @param params - Transfer parameters * @param params.tokenPublicKey - The token's public key * @param params.receiverSparkAddress - The recipient's Spark address * @param params.tokenAmount - Amount of tokens to transfer * @param params.isTaproot - Whether to use Taproot (defaults to false) * @returns Promise resolving to transaction hash */ transferTokens(params: { tokenPublicKey: string; receiverSparkAddress: string; tokenAmount: number; isTaproot?: boolean; }): Promise; /** * Generic RPC method for custom requests * @param method - The RPC method name * @param params - Optional parameters for the method * @returns Promise resolving to the method result */ request(method: string, params?: unknown): Promise; /** Additional properties that providers may implement */ [key: string]: unknown; } /** * Result from wallet connection, supporting different naming conventions */ export type SparkConnectionResult = { sparkAddress: string; sparkTaprootAddress?: string; } | { address: string; taprootAddress?: string; }; /** * Result from address retrieval, supporting different formats */ export type SparkAddressResult = SparkConnectionResult | string; /** * Message signing request, supporting both simple and advanced options */ export type SparkSignMessageRequest = { message: string; isTaproot?: boolean; } | string; /** * Result from message signing, supporting different return formats */ export type SparkSignatureResult = { signature: string; } | string;