import * as btc from "@scure/btc-signer"; import type { BitcoinMerkleProofResponse, BitcoinTransaction, UTXO } from "../types/bitcoin.js"; import { type UtxoDepositProof, type UtxoPlanOverrides, type UtxoWithdrawalPlan } from "../utxo/index.js"; /** * Bitcoin service for proof generation and network queries * * Provides comprehensive Bitcoin network integration including: * - Merkle proof generation for deposit verification * - UTXO selection and transaction construction * - Network communication with Blockstream API * - Address validation and script generation * * Mirrors the functionality from the Rust SDK's btc-utils * * @example * ```typescript * const bitcoinService = new BitcoinService( * "https://blockstream.info/api", * "mainnet" * ) * * // Generate merkle proof for deposit verification * const proof = await bitcoinService.fetchMerkleProof(txHash) * * // Select UTXOs for withdrawal transaction * const plan = bitcoinService.buildWithdrawalPlan(utxos, amount, targetAddress, changeAddress, feeRate) * ``` */ export declare class BitcoinService { private apiUrl; private network; /** * Create a new BitcoinService instance * @param apiUrl - Bitcoin API endpoint (e.g., "https://blockstream.info/api") * @param network - Bitcoin network type ("mainnet" or "testnet") */ constructor(apiUrl: string, network: "mainnet" | "testnet", rpcConfig?: { url: string; headers?: Record; }); private rpc; /** * Fetch merkle proof for Bitcoin transaction verification * * Used to prove Bitcoin transaction inclusion in a block for deposit verification. * The merkle proof allows NEAR contracts to verify Bitcoin transactions without * running a full Bitcoin node. * * @param txHash - Bitcoin transaction hash (64-character hex string) * @returns Promise resolving to merkle proof data including block height, position, and proof hashes * @throws {Error} When API request fails or transaction not found * * @example * ```typescript * const proof = await bitcoinService.fetchMerkleProof( * "a1b2c3d4e5f6789012345678901234567890abcdef1234567890abcdef123456" * ) * console.log(`Block height: ${proof.block_height}`) * console.log(`Position in block: ${proof.pos}`) * console.log(`Merkle proof: ${proof.merkle}`) * ``` */ fetchMerkleProof(txHash: string): Promise; getMerkleProof(txHash: string): Promise; getDepositProof(txHash: string, vout: number): Promise; /** * Plan a simple Bitcoin transaction using manual UTXO selection. * * The planner applies largest-first selection with configurable fee logic. * It produces the exact inputs that should be consumed, along with the * canonical outputs (recipient + optional change) that must be encoded on * chain when the NEAR connector constructs the unsigned transaction. */ buildWithdrawalPlan(utxos: UTXO[], amount: bigint, targetAddress: string, changeAddress: string, feeRate?: number, overrides?: UtxoPlanOverrides): UtxoWithdrawalPlan; private normalizeUtxos; private createFeeCalculator; private buildOutputs; private createOutput; /** * Get raw transaction bytes for proof generation and verification * * Fetches the complete transaction data in binary format, required for: * - Merkle proof verification in NEAR contracts * - Bitcoin transaction parsing and validation * - Digital signature verification * * @param txHash - Bitcoin transaction hash * @returns Promise resolving to raw transaction bytes * @throws {Error} When transaction not found or API error */ getTransactionBytes(txHash: string): Promise; /** * Broadcast signed transaction to Bitcoin network * * Submits a fully signed Bitcoin transaction to the network for confirmation. * Used in the final step of withdrawal flow after MPC signing. * * @param txHex - Signed transaction in hexadecimal format * @returns Promise resolving to transaction hash (txid) if successful * @throws {Error} When broadcast fails (insufficient fees, double spend, etc.) * * @example * ```typescript * const signedTxHex = "0200000001abc123..." // From MPC signing * const txHash = await bitcoinService.broadcastTransaction(signedTxHex) * console.log(`Transaction broadcast: ${txHash}`) * ``` */ broadcastTransaction(txHex: string): Promise; /** * Get detailed Bitcoin transaction information * * Fetches comprehensive transaction data including inputs, outputs, fees, * and confirmation status. Used for deposit verification and withdrawal tracking. * * @param txHash - Bitcoin transaction hash * @returns Promise resolving to complete transaction details * @throws {Error} When transaction not found or API error * * @example * ```typescript * const tx = await bitcoinService.getTransaction("abc123...") * console.log(`Confirmed: ${tx.status?.confirmed}`) * console.log(`Block height: ${tx.status?.block_height}`) * console.log(`Fee: ${tx.fee} satoshis`) * ``` */ getTransaction(txHash: string): Promise; /** * Get transaction hex for parsing */ private getTransactionHex; /** * Get scure-btc-signer network configuration * * Returns the appropriate network configuration object for use with * scure-btc-signer library functions (address parsing, transaction signing, etc.) * * @returns Network configuration object (btc.NETWORK for mainnet, btc.TEST_NETWORK for testnet) */ getNetwork(): typeof btc.NETWORK | typeof btc.TEST_NETWORK; /** * Converts a Bitcoin address to its corresponding script_pubkey * @param address - Bitcoin address string * @returns script_pubkey encoded as a hex string */ addressToScriptPubkey(address: string): string; } //# sourceMappingURL=bitcoin.d.ts.map