BitcoinerLab Descriptors API - v3.1.7
    Preparing search index...

    Function DescriptorsFactory

    • Constructs the necessary functions and classes for working with descriptors, using either an external elliptic curve (ecc) library or a core Bitcoin library (e.g. bitcoinjs-lib or @scure/btc-signer).

      Note: Most users do not need to call DescriptorsFactory(...) directly.

      • @bitcoinerlab/descriptors already provides the bitcoinjs-ready defaults.
      • @bitcoinerlab/descriptors-scure already provides the scure-ready defaults.

      This factory is mainly useful for:

      • backwards compatibility with pre-3.1.x bitcoinjs usage, and
      • advanced bitcoinjs usage where you want to bind a custom BitcoinLib backend adapter.

      It is not the recommended public entry point for users of @bitcoinerlab/descriptors. It remains in core because the preset packages and their compatibility layers are built on top of it. Future major versions are expected to stop re-exporting it from those preset packages.

      Notably, it returns the Output class, which provides methods to create, sign, and finalize transactions from descriptor expressions.

      The factory also returns utility methods like expand (detailed below) and parseKeyExpression (see KeyExpressionParser).

      Additionally, for convenience, the factory returns BIP32 and ECPair. In bitcoinjs mode, these are the already initialized bitcoinjs factories, equivalent to BIP32 = BIP32Factory(ecc) and ECPair = ECPairFactory(ecc). When using scure, prefer scure-native key types (HDKey and Uint8Array for private keys), which do not require key-factory initialization.

      Parameters

      • bitcoinLib: BitcoinLib

        A pre-built BitcoinLib backend adapter.

        For example, the current 3.x bitcoinjs preset still allows binding a custom bitcoinjs-compatible ecc implementation:

        import * as ecc from '@bitcoinerlab/secp256k1';
        import { DescriptorsFactory, createBitcoinjsLib } from '@bitcoinerlab/descriptors';

        const { Output } = DescriptorsFactory(createBitcoinjsLib(ecc));

      Returns {
          Output: typeof Output;
          parseKeyExpression: KeyExpressionParser;
          expand: (
              params: {
                  descriptor: string;
                  index?: number;
                  change?: number;
                  checksumRequired?: boolean;
                  network?: Network;
                  allowMiniscriptInP2SH?: boolean;
              },
          ) => Expansion;
          ECPair: ECPairAPI;
          BIP32: BIP32API;
      }

      • Output: typeof Output
      • parseKeyExpression: KeyExpressionParser

        Takes a string key expression (xpub, xprv, pubkey or wif) and parses it

      • expand: (
            params: {
                descriptor: string;
                index?: number;
                change?: number;
                checksumRequired?: boolean;
                network?: Network;
                allowMiniscriptInP2SH?: boolean;
            },
        ) => Expansion
      • ECPair: ECPairAPI
      • BIP32: BIP32API