Skip to content
Javascript library for working with bitcoin, esp. validation & multisig.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
src Added ESLint, updated babel. Nov 8, 2019
.eslintrc.json Added ESLint, updated babel. Nov 8, 2019
.gitignore moved from private repo Nov 5, 2019
.npmignore added jsdocs Nov 7, 2019
.npmrc.template added steps to publish npm registry Nov 6, 2019
LICENSE updated copyright date Nov 11, 2019 updated links in Nov 7, 2019
package-lock.json 0.0.5 Nov 8, 2019
package.json 0.0.5 Nov 8, 2019

Unchained Capital Bitcoin Utilities

Build Status

This library builds on the excellent bitcoinjs-lib, adding valuable but missing functionality for validation, HD wallets, block explorers, and especially multisig.

Full API documentation can be found at unchained-bitcoin.

This library was built and is maintained by Unchained Capital.


unchained-bitcoin is distributed as an NPM package. Add it to your application's dependencies:

$ npm install --save unchained-bitcoin


The library provides a functional API which builds upon data structures used by bitcoinjs-lib.

In particular, many functions accept a multisig argument which is the kind of object returned by functions such as bitcoin.payments.p2ms, bitcoin.payments.p2sh, &c. from bitcoinjs-lib.

The examples below provide an initial idea of how to use this library, but see the API documentation for full details.

Interacting with a multisig address.

Generating multisigs

Multisignature objects can be generated with two functions:

  • generateMultisigFromPublicKeys -- useful when directly passing public keys
  • generateMultisigFromHex -- useful when parsing an existing redeem script

Each of these functions accepts additional arguments which determines the multisig address type (e.g. P2SH or P2WSH).

import {
	P2SH,                      // or: P2SH_P2WSH, P2WSH
	MAINNET,                   // or: TESTNET
} from "unchained-bitcoin";

// Public keys are represented as compressed hex.
const publicKeys = [

// A mainnet P2SH 2-of-3 multisig.
const multisig = generateMultisigFromPublicKeys(MAINNET, P2SH, 2, ...publicKeys);

Querying multisigs

The multisig object above can be passed around and queried with other functions in the API.

multisigAddress(multisig); // Returns public address
multisigAddressType(multisig); // P2SH
multisigRequiredSigners(multisig); // 2
multisigTotalSigners(multisig); // 3
multisigRedeemScript(multisig); // Returns redeem script in hex
multisigWitnessScript(multisig); // Returns witness script in hex (null for P2SH)
multisigPublicKeys(multisig); // Returns publicKeys


This library contains several useful functions for validation not provided by bitcoinjs-lib or other libraries. The validation functions are designed to return an empty string '' on valid input and provide a helpful error message otherwise.

  • validateAddress -- understands Bech32 addresses and is aware of differences in addresses across networks

  • valdiateBIP32Path -- understands absolute and relative BIP32 paths, validates maximum BIP32 index values, and can optionally check for fully hardened or unhardened paths

  • validateExtendedPublicKey -- understands network-dependent differences in encoding extended public keys

  • validatePublicKey -- allows any hexadecimal value

  • validateFeeRate -- implements a reasonable maximum fee rate in Satoshis/byte

  • validateFee -- implements a reasonable maximum fee in BTC

  • validateOutputAmount -- checks for dust and that amount is less than total input amount

  • validateMultisigSignature -- checks signatures for correctness and works across all multisig address types


Developers who want to work on this library should clone the source code and install dependencies:

$ git clone`
$ cd unchained-bitcoin
$ npm install


Unit tests are implemented in Jest and can be run via

$ npm test


Unchained Capital welcomes bug reports, new features, and better documentation for this library.

If you are fixing a bug or adding a feature, please first check the GitHub issues page to see if there is any existing discussion about it.

To contribute, create a pull request (PR) on GitHub against the Unchained Capital fork of unchained-bitcoin.

Before you submit your PR, make sure to update and run the test suite!

You can’t perform that action at this time.