@bitcoinerlab/coinselect
Version:
A TypeScript library for Bitcoin transaction management, based on Bitcoin Descriptors for defining inputs and outputs. It facilitates optimal UTXO selection and transaction size calculation.
48 lines (47 loc) • 1.78 kB
TypeScript
import type { PartialSig } from 'bip174';
import type { OutputInstance } from '@bitcoinerlab/descriptors';
export declare const isSegwitTx: (inputs: Array<OutputInstance>) => boolean;
/**
* Computes the virtual size (vsize) of a Bitcoin transaction based on specified
* inputs and outputs.
*
* @returns The computed virtual size (vsize) of the transaction, rounded up to
* the nearest integer.
*
* *NOTE:* When the descriptor in an input is `addr(address)`, it is assumed
* that any `addr(SH_TYPE_ADDRESS)` is in fact a Segwit `SH_WPKH`
* (Script Hash-Witness Public Key Hash).
* For inputs using arbitrary scripts (not standard addresses),
* use a descriptor in the format `sh(MINISCRIPT)`.
* Similarly, add(TR_TYPE_ADDRESS) is assumed to be a single-key tr address.
*
* @example
* ```
* const vsizeValue = vsize(
* [new Output({ descriptor: 'addr(...)' })], // inputs
* [new Output({ descriptor: 'addr(...)' })] // outputs
* );
* ```
*
* @see {@link https://bitcoinerlab.com/modules/descriptors} for details on
* OutputInstance and descriptors.
*/
export declare function vsize(
/**
* Array of `OutputInstance` representing the inputs of the transaction.
*/
inputs: Array<OutputInstance>,
/**
* Array of `OutputInstance` representing the outputs of the transaction.
*/
outputs: Array<OutputInstance>,
/**
* Optional array of arrays containing signatures.
* The outer array corresponds to each input in the transaction. The inner array contains
* signatures for each public key associated with the respective input.
*
* If provided, enables calculation of exact signature sizes.
* Defaults to assuming 72 bytes per signature.
* Mainly used for testing and accurate fee estimation.
*/
signaturesPerInput?: Array<Array<PartialSig>>): number;