@xchainjs/xchain-bitcoincash
Version:
Custom bitcoincash client and utilities used by XChainJS clients
72 lines (71 loc) • 3.29 kB
TypeScript
import { FeeRate, TxHash } from '@xchainjs/xchain-client';
import { Address } from '@xchainjs/xchain-util';
import { TxParams, UTXO, UtxoSelectionPreferences } from '@xchainjs/xchain-utxo';
import { Client } from './client';
/**
* Custom Bitcoin client extended to support keystore functionality
*/
declare class ClientKeystore extends Client {
/**
* @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 BitcoinCash address.
* @throws {"Phrase must be provided"} Thrown if the phrase has not been set before.
*/
getAddressAsync(index?: number): Promise<string>;
/**
* Private function to get BCH keys.
* Generates a key pair from the provided phrase and derivation path.
* @param {string} phrase - The phrase used for generating the private key.
* @param {string} derivationPath - The BIP44 derivation path.
* @returns {PrivateKey} The key pair generated from the phrase and derivation path.
*
* @throws {"Invalid phrase"} Thrown if an invalid phrase is provided.
* */
private getBCHKeys;
/**
* Transfer BCH.
* @param {TxParams & { feeRate?: FeeRate; utxoSelectionPreferences?: UtxoSelectionPreferences }} params - The transfer options.
* @returns {Promise<TxHash>} A promise that resolves with the transaction hash.
*/
transfer(params: TxParams & {
feeRate?: FeeRate;
utxoSelectionPreferences?: UtxoSelectionPreferences;
selectedUtxos?: UTXO[];
}): Promise<TxHash>;
/**
* Transfer the maximum amount of BCH (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 };