@bitcoinerlab/descriptors - v3.0.5
    Preparing search index...

    Class Output

    The Output class is the central component for managing descriptors. It facilitates the creation of outputs to receive funds and enables the signing and finalization of PSBTs (Partially Signed Bitcoin Transactions) for spending UTXOs (Unspent Transaction Outputs).

    Index

    Constructors

    • Parameters

      • options: {
            descriptor: string;
            index?: number;
            change?: number;
            checksumRequired?: boolean;
            allowMiniscriptInP2SH?: boolean;
            network?: Network;
            preimages?: Preimage[];
            signersPubKeys?: Uint8Array<ArrayBufferLike>[];
            taprootSpendPath?: "script" | "key";
            tapLeaf?: string | Uint8Array<ArrayBufferLike>;
        }
        • descriptor: string

          The descriptor string in ASCII format. It may include a "*" to denote an arbitrary index (aka ranged descriptors).

        • Optionalindex?: number

          The descriptor's index in the case of a range descriptor (must be an integer >=0).

          This Output class always models a concrete spendable output. If the descriptor contains any wildcard (*), an index is required.

        • Optionalchange?: number

          Multipath branch selector for key-path tuples like /<0;1>/*.

          The value passed in change must be one of the numbers present in the tuple.

          Examples:

          • /<0;1>/* accepts change: 0 (typically receive) or change: 1 (typically change).
          • /<0;1;2>/* accepts change: 0, 1 or 2.

          This parameter is independent from index: change resolves multipath tuples, while index resolves the final wildcard *.

        • OptionalchecksumRequired?: boolean

          An optional flag indicating whether the descriptor is required to include a checksum.

          false
          
        • OptionalallowMiniscriptInP2SH?: boolean

          A flag indicating whether this instance can parse and generate script satisfactions for sh(miniscript) top-level expressions of miniscripts. This is not recommended.

          false
          
        • Optionalnetwork?: Network

          One of bitcoinjs-lib networks (or another one following the same interface).

          networks.bitcoin
          
        • Optionalpreimages?: Preimage[]

          An array of preimages if the miniscript-based descriptor uses them.

          This info is necessary to finalize Psbts. Leave it undefined if your miniscript-based descriptor does not use preimages or you don't know or don't wanto use them.

          You can also leave it undefined if only need to generate the scriptPubKey or address for a descriptor.

          []

        • OptionalsignersPubKeys?: Uint8Array<ArrayBufferLike>[]

          An array of the public keys used for signing the transaction when spending the previous output associated with this descriptor.

          This parameter is only used if the descriptor object is being used to finalize a transaction. It is necessary to specify the spending path when working with miniscript-based expressions that have multiple spending paths.

          Set this parameter to an array containing the public keys involved in the desired spending path. Leave it undefined if you only need to generate the scriptPubKey or address for a descriptor, or if all the public keys involved in the descriptor will sign the transaction. In the latter case, the satisfier will automatically choose the most optimal spending path (if more than one is available). If omitted, this library assumes that all keys in the miniscript can sign. For taproot script-path spends, keys are inferred per leaf.

          For more details on using this parameter, refer to this Stack Exchange answer.

        • OptionaltaprootSpendPath?: "script" | "key"

          Taproot spend path policy. Use key to force key-path estimation, or script to estimate script-path spends.

          This setting only applies to tr(KEY,TREE) descriptors. For tr(KEY) descriptors, only key-path is available.

          When script is selected:

          • if tapLeaf is provided, that leaf is used.
          • if tapLeaf is omitted, the satisfier auto-selects the leaf with the smallest witness among satisfiable candidates.

          Default policy is script for tr(KEY,TREE) and key for key-only taproot descriptors (tr(KEY) and addr(TR_ADDRESS)).

        • OptionaltapLeaf?: string | Uint8Array<ArrayBufferLike>

          Optional taproot leaf selector (tapleaf hash or miniscript string). Only used when taprootSpendPath is script and descriptor is tr(KEY,TREE). If omitted, the smallest satisfiable leaf is selected.

      Returns Output

      • when descriptor is invalid

    Methods

    • Returns the compiled Script Satisfaction for a miniscript-based Output. The satisfaction is the unlocking script, derived by the Satisfier algorithm (https://bitcoin.sipa.be/miniscript/).

      This method uses a two-pass flow:

      1. Planning: constraints (nLockTime/nSequence) are computed using fake signatures. This is done since the final solution may not need all the signatures in signersPubKeys. And we may avoid the user do extra signing (tedious op with HWW).
      2. Signing: the provided signatures are used to build the final satisfaction, while enforcing the planned constraints so the same solution is selected. Not all the signatures of signersPubKeys may be required.

      The return value includes the satisfaction script and the constraints.

      Parameters

      • signatures: PartialSig[]

        An array with all the signatures needed to build the Satisfaction of this miniscript-based Output.

        signatures must be passed using this format (pairs of pubKey/signature): interface PartialSig { pubkey: Uint8Array; signature: Uint8Array; }

      Returns {
          scriptSatisfaction: Uint8Array;
          nLockTime: number | undefined;
          nSequence: number | undefined;
      }

    • Returns the taproot script‑path satisfaction for a tap miniscript descriptor. This mirrors getScriptSatisfaction and uses the same two‑pass plan/sign flow.

      In addition to nLockTime/nSequence, it returns the selected tapLeafHash (the leaf chosen during planning) and the leaf’s tapscript.

      Parameters

      • signatures: PartialSig[]

        An array with all the signatures needed to build the Satisfaction of this miniscript-based Output.

        signatures must be passed using this format (pairs of pubKey/signature): interface PartialSig { pubkey: Uint8Array; signature: Uint8Array; }

      Returns TaprootLeafSatisfaction

    • Creates and returns an instance of bitcoinjs-lib Payment's interface with the scriptPubKey of this Output.

      Returns Payment

    • Returns the Bitcoin Address of this Output.

      Returns string

    • Returns this Output's scriptPubKey.

      Returns Uint8Array

    • Gets the nSequence required to fulfill this Output.

      Returns number | undefined

    • Gets the nLockTime required to fulfill this Output.

      Returns number | undefined

    • Returns the tapleaf hash selected during planning for taproot script-path spends. If signersPubKeys are provided, selection is optimized for those pubkeys. If a specific tapLeaf selector is used in spending calls, this reflects that selection.

      Returns Uint8Array<ArrayBufferLike> | undefined

    • Gets the witnessScript required to fulfill this Output. Only applies to Segwit outputs.

      Returns Uint8Array<ArrayBufferLike> | undefined

    • Gets the redeemScript required to fullfill this Output. Only applies to SH outputs: sh(wpkh), sh(wsh), sh(lockingScript).

      Returns Uint8Array<ArrayBufferLike> | undefined

    • Whether this Output is Segwit.

      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).

      Returns boolean | undefined

    • Whether this Output is Taproot.

      Returns boolean | undefined

    • Attempts to determine the type of output script by testing it against various payment types.

      This method tries to identify if the output is one of the following types:

      • P2SH (Pay to Script Hash)
      • P2WSH (Pay to Witness Script Hash)
      • P2WPKH (Pay to Witness Public Key Hash)
      • P2PKH (Pay to Public Key Hash)
      • P2TR (Pay to Taproot)

      Returns {
          isPKH: boolean;
          isWPKH: boolean;
          isSH: boolean;
          isWSH: boolean;
          isTR: boolean;
      }

      An object { isPKH: boolean; isWPKH: boolean; isSH: boolean; isWSH: boolean; isTR: boolean;} with boolean properties indicating the detected output type

    • Computes the Weight Unit contributions of this Output as if it were the input in a tx.

      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). , Also any addr(SINGLE_KEY_ADDRESS) * is assumed to be a single key Taproot address (like those defined in BIP86). For inputs using arbitrary scripts (not standard addresses), use a descriptor in the format sh(MINISCRIPT), wsh(MINISCRIPT) or tr(KEY,TREE) for taproot script-path expressions.

      Parameters

      Returns number

    • Computes the Weight Unit contributions of this Output as if it were the output in a tx.

      Returns number

    • Sets this output as an input of the provided psbt and updates the psbt locktime if required by the descriptor.

      psbt and vout are mandatory. Include txHex as well. The pair vout and txHex define the transaction and output number this instance pertains to.

      Though not advised, for Segwit inputs you can pass txId and value in lieu of txHex. If doing so, ensure value accuracy to avoid potential fee attacks - See this issue.

      Note: Hardware wallets need the full txHex for Segwit.

      When unsure, always use txHex, and skip txId and value for safety.

      Use rbf to mark whether this tx can be replaced with another with higher fee while being in the mempool. Note that a tx will automatically be marked as replacable if a single input requests it. Note that any transaction using a relative timelock (nSequence < 0x80000000) also falls within the RBF range (nSequence < 0xFFFFFFFE), making it inherently replaceable. So don't set rbf to false if this is tx uses relative time locks.

      Parameters

      • __namedParameters: {
            psbt: Psbt;
            txHex?: string;
            txId?: string;
            value?: bigint;
            vout: number;
            rbf?: boolean;
        }

      Returns (__namedParameters: { psbt: Psbt; validate?: boolean }) => void

      A finalizer function to be used after signing the psbt. This function ensures that this input is properly finalized. The finalizer completes the PSBT input by adding the unlocking script (scriptWitness or scriptSig) that satisfies this Output's spending conditions. Because these scripts include signatures, you should finish all signing operations before calling the finalizer. The finalizer has this signature:

      ( { psbt, validate = true } : { psbt: Psbt; validate: boolean | undefined } ) => void

    • Adds this output as an output of the provided psbt with the given value.

      Parameters

      • params: { psbt: Psbt; value: bigint }

        The parameters for the method.

        • psbt: Psbt

          The Partially Signed Bitcoin Transaction.

        • value: bigint

          The value for the output in satoshis.

      Returns void

    • Decomposes the descriptor used to form this Output into its elemental parts. See ExpansionMap for a detailed explanation.

      Returns {
          expandedExpression?: string;
          miniscript?: string;
          expandedMiniscript?: string;
          tapTreeExpression?: string;
          tapTree?: TapTreeNode;
          tapTreeInfo?: TapTreeInfoNode;
          expansionMap?: ExpansionMap;
      }