UNPKG

@xchainjs/xchain-bitcoin

Version:

Custom Bitcoin client and utilities used by XChainJS clients

78 lines (77 loc) 3.45 kB
import { FeeRate, TxHash } from '@xchainjs/xchain-client'; import { Address } from '@xchainjs/xchain-util'; import { TxParams, UTXO, UtxoClientParams, UtxoSelectionPreferences } from '@xchainjs/xchain-utxo'; import { Client } from './client'; import { AddressFormat } from './types'; /** * Custom Bitcoin client extended to support keystore functionality */ declare class ClientKeystore extends Client { constructor(params?: UtxoClientParams & { addressFormat?: AddressFormat; }); /** * @deprecated This function eventually will be removed. Use getAddressAsync instead. * Get the address associated with the given index. * @param {number} index The index of the address. * @returns {Address} The Bitcoin address. * @throws {"index must be greater than zero"} Thrown if the index is less than zero. * @throws {"Phrase must be provided"} Thrown if the phrase has not been set before. * @throws {"Address not defined"} Thrown if failed to create the address from the phrase. */ getAddress(index?: number): Address; /** * Get the current address asynchronously. * @param {number} index The index of the address. * @returns {Promise<Address>} A promise that resolves to the Bitcoin address. * @throws {"Phrase must be provided"} Thrown if the phrase has not been set before. */ getAddressAsync(index?: number): Promise<string>; /** * @private * Get the Bitcoin keys derived from the given phrase. * * @param {string} phrase The phrase to be used for generating the keys. * @param {number} index The index of the address. * @returns {Bitcoin.ECPair.ECPairInterface} The Bitcoin key pair. * @throws {"Could not get private key from phrase"} Thrown if failed to create BTC keys from the given phrase. */ private getBtcKeys; /** * Transfer BTC. * * @param {TxParams&FeeRate} params The transfer options including the fee rate. * @returns {Promise<TxHash>} A promise that resolves to the transaction hash. * @throws {"memo too long"} Thrown if the memo is longer than 80 characters. */ transfer(params: TxParams & { feeRate?: FeeRate; utxoSelectionPreferences?: UtxoSelectionPreferences; selectedUtxos?: UTXO[]; }): Promise<TxHash>; /** * Transfer the maximum amount of Bitcoin (sweep). * * Calculates the maximum sendable amount after fees, signs, and broadcasts the transaction. * @param {Object} params The transfer parameters. * @param {string} params.recipient The recipient address. * @param {string} [params.memo] Optional memo for the transaction. * @param {FeeRate} [params.feeRate] Optional fee rate. Defaults to 'fast' rate. * @param {number} [params.walletIndex] Optional wallet index. Defaults to 0. * @param {UtxoSelectionPreferences} [params.utxoSelectionPreferences] Optional UTXO selection preferences. * @returns {Promise<{ hash: TxHash; maxAmount: number; fee: number }>} The transaction hash, amount sent, and fee. */ transferMax(params: { recipient: Address; memo?: string; feeRate?: FeeRate; walletIndex?: number; utxoSelectionPreferences?: UtxoSelectionPreferences; selectedUtxos?: UTXO[]; }): Promise<{ hash: TxHash; maxAmount: number; fee: number; }>; } export { ClientKeystore };