UNPKG

@btc-stamps/tx-builder

Version:

Transaction builder for Bitcoin Stamps and SRC-20 tokens with advanced UTXO selection

112 lines (108 loc) 2.7 kB
import { Network } from 'bitcoinjs-lib'; import { Buffer } from 'node:buffer'; /** * UTXO Provider Interface * Defines the contract for fetching UTXOs from various sources */ interface UTXO { txid: string; vout: number; value: number; scriptPubKey: string; confirmations?: number; height?: number; timestamp?: number; address?: string; witnessUtxo?: { script: Buffer; value: number; }; nonWitnessUtxo?: Buffer; } interface Balance { confirmed: number; unconfirmed: number; total: number; } interface Transaction { txid: string; hex: string; confirmations: number; height?: number; timestamp?: number; fee?: number; size?: number; vsize?: number; } interface AddressHistory { txid: string; height: number; fee?: number; } interface AddressHistoryOptions { fromHeight?: number; toHeight?: number; limit?: number; } interface IUTXOProvider { /** * Get UTXOs for a given address */ getUTXOs(address: string): Promise<UTXO[]>; /** * Get balance for a given address */ getBalance(address: string): Promise<Balance>; /** * Get transaction by ID */ getTransaction(txid: string): Promise<Transaction>; /** * Broadcast a signed transaction */ broadcastTransaction(hexTx: string): Promise<string>; /** * Get current fee rate (sat/vB) */ getFeeRate(priority?: 'low' | 'medium' | 'high'): Promise<number>; /** * Get current block height */ getBlockHeight(): Promise<number>; /** * Get address transaction history */ getAddressHistory(address: string, options?: AddressHistoryOptions): Promise<AddressHistory[]>; /** * Check if provider is connected */ isConnected(): Promise<boolean>; /** * Get network this provider is connected to */ getNetwork(): Network; } interface ProviderOptions { network: Network; timeout?: number; retries?: number; retryDelay?: number; maxRetryDelay?: number; } interface ElectrumXOptions extends ProviderOptions { host?: string; port?: number; protocol?: 'tcp' | 'ssl' | 'ws' | 'wss'; endpoints?: Array<{ host: string; port: number; protocol: 'tcp' | 'ssl' | 'ws' | 'wss'; priority?: number; maxRetries?: number; timeout?: number; }>; fallbackToPublic?: boolean; connectionTimeout?: number; requestTimeout?: number; } export type { AddressHistoryOptions as A, Balance as B, ElectrumXOptions as E, IUTXOProvider as I, ProviderOptions as P, Transaction as T, UTXO as U, AddressHistory as a };