npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

bitroot

v1.0.0

Published

Bitcoin Taproot toolkit for Node.js - create addresses, sign transactions, and manage Taproot UTXOs

Downloads

34

Readme

Bitroot 🌱

A comprehensive Bitcoin Taproot library for Node.js

Bitroot is a modern, easy-to-use library for creating and managing Bitcoin Taproot (P2TR) addresses and transactions. Built on top of bitcoinjs-lib, it provides a clean API for working with Bitcoin's latest address format.

Features

  • ✨ BIP86 HD Wallets - Generate hierarchical deterministic wallets using BIP39 mnemonics
  • 🔐 Taproot Addresses - Create and manage P2TR addresses (bc1p...)
  • ✍️ Schnorr Signatures - Sign transactions and messages with Schnorr signatures
  • 💸 Transaction Building - Build, sign, and broadcast Taproot transactions
  • 🌐 Network Support - Mainnet, testnet, and regtest
  • 📦 TypeScript - Full TypeScript support with type definitions

Installation

npm install bitroot

Quick Start

Generate a new wallet

import { TaprootWallet } from 'bitroot';

// Generate new mnemonic
const mnemonic = TaprootWallet.generateMnemonic(); // 12 words
console.log('Mnemonic:', mnemonic);

// Create wallet from mnemonic
const wallet = new TaprootWallet({ 
  network: 'testnet',
  mnemonic 
});

// Get first address
const address = wallet.getAddress(0, 0);
console.log('Address:', address.address);
console.log('Public Key:', address.publicKey);
console.log('Path:', address.path);

Create address from private key

import { TaprootAddress } from 'bitroot';
import * as crypto from 'crypto';

const address = new TaprootAddress('testnet');

// Generate random private key (32 bytes)
const privateKey = crypto.randomBytes(32);

// Create address
const addressInfo = address.fromPrivateKey(privateKey);
console.log('Address:', addressInfo.address);
console.log('Tweaked Public Key:', addressInfo.tweakedPublicKey);

Build and sign transaction

import { TaprootTransaction } from 'bitroot';

const tx = new TaprootTransaction('testnet');

// Create transaction
const signedTx = await tx.create({
  inputs: [
    {
      utxo: {
        txid: 'your_utxo_txid',
        vout: 0,
        value: 100000, // satoshis
      },
      privateKey: yourPrivateKey,
    }
  ],
  outputs: [
    {
      address: 'recipient_address',
      value: 90000, // satoshis
    }
  ],
  feeRate: 1, // sat/vB
});

console.log('Transaction ID:', signedTx.txid);
console.log('Transaction Hex:', signedTx.hex);
console.log('Fee:', signedTx.fee, 'sats');
console.log('Size:', signedTx.vsize, 'vB');

Simple send transaction

import { TaprootTransaction } from 'bitroot';

const tx = new TaprootTransaction('testnet');

// Send bitcoin
const signedTx = await tx.send(
  {
    utxos: [
      {
        txid: 'your_utxo_txid',
        vout: 0,
        value: 100000,
      }
    ],
    privateKey: yourPrivateKey,
  },
  'recipient_address',
  50000, // amount in satoshis
  {
    feeRate: 1,
    changeAddress: 'your_change_address', // optional
  }
);

console.log('Sent! TXID:', signedTx.txid);

Sign and verify messages

import { TaprootSigner } from 'bitroot';

const signer = new TaprootSigner('testnet');

// Sign message
const message = 'Hello, Taproot!';
const signature = signer.signMessage(message, privateKey);

console.log('Signature:', signature.toString('hex'));

// Verify signature
const publicKey = getYourPublicKey();
const isValid = signer.verifyMessage(message, signature, publicKey);

console.log('Valid:', isValid);

API Reference

TaprootWallet

HD Wallet implementation following BIP86 (Taproot) standard.

class TaprootWallet {
  constructor(options?: WalletOptions)
  static generateMnemonic(strength?: 128 | 256): string
  static validateMnemonic(mnemonic: string): boolean
  fromMnemonic(mnemonic: string): void
  fromSeed(seed: Buffer): void
  getAddress(accountIndex?: number, addressIndex?: number, isChange?: boolean): AddressInfo
  getAddresses(count: number, accountIndex?: number, startIndex?: number, isChange?: boolean): AddressInfo[]
  getPrivateKey(accountIndex?: number, addressIndex?: number, isChange?: boolean): Buffer
  getPublicKey(accountIndex?: number, addressIndex?: number, isChange?: boolean): Buffer
  getKeyPair(accountIndex?: number, addressIndex?: number, isChange?: boolean): TaprootKeyPair
  exportXpub(): string
  exportXprv(): string
  getMasterFingerprint(): string
}

TaprootAddress

Taproot address generation and validation.

class TaprootAddress {
  constructor(network?: 'mainnet' | 'testnet' | 'regtest')
  fromPublicKey(publicKey: Buffer): AddressInfo
  fromPrivateKey(privateKey: Buffer): AddressInfo
  fromScriptTree(internalPubkey: Buffer, scriptTree: Taptree): AddressInfo
  decode(address: string): Buffer
  isValid(address: string): boolean
  getInfo(address: string): { outputScript: string; type: string }
}

TaprootTransaction

Build and sign Taproot transactions.

class TaprootTransaction {
  constructor(network?: 'mainnet' | 'testnet' | 'regtest')
  create(options: TransactionOptions): Promise<SignedTransaction>
  send(from: { utxos: UTXO[], privateKey: Buffer }, to: string, amount: number, options?: { feeRate?: number, changeAddress?: string }): Promise<SignedTransaction>
  createPsbt(options: TransactionOptions): Psbt
  signPsbt(psbt: Psbt, privateKeys: Buffer[]): Psbt
  decode(txHex: string): Transaction
  getInfo(tx: Transaction): TransactionInfo
}

TaprootSigner

Sign transactions and messages with Schnorr signatures.

class TaprootSigner {
  constructor(network?: 'mainnet' | 'testnet' | 'regtest')
  tweakPrivateKey(privateKey: Buffer): Buffer
  signInput(psbt: Psbt, inputIndex: number, privateKey: Buffer, sighashTypes?: number[]): void
  signAllInputs(psbt: Psbt, privateKey: Buffer, sighashTypes?: number[]): void
  signMessage(message: string | Buffer, privateKey: Buffer): Buffer
  verifyMessage(message: string | Buffer, signature: Buffer, publicKey: Buffer): boolean
  createKeyPair(privateKey: Buffer): TaprootKeyPair
}

Types

interface AddressInfo {
  address: string;
  publicKey: string;
  tweakedPublicKey: string;
  path?: string;
}

interface UTXO {
  txid: string;
  vout: number;
  value: number;
  scriptPubKey?: string;
}

interface SignedTransaction {
  txid: string;
  hex: string;
  fee: number;
  size: number;
  vsize: number;
}

interface TaprootKeyPair {
  privateKey: Buffer;
  publicKey: Buffer;
  tweakedPrivateKey: Buffer;
  tweakedPublicKey: Buffer;
}

Utilities

// Network helpers
getNetwork(network: 'mainnet' | 'testnet' | 'regtest'): Network

// Address validation
isValidAddress(address: string, network?: string): boolean
isTaprootAddress(address: string, network?: string): boolean

// Conversion utilities
hexToBuffer(hex: string): Buffer
bufferToHex(buffer: Buffer): string
satoshiToBTC(satoshi: number): number
btcToSatoshi(btc: number): number

// Transaction utilities
calculateVSize(transaction: Transaction): number
calculateFee(transaction: Transaction, feeRate: number): number

Security Considerations

⚠️ Important Security Notes:

  1. Never share your private keys or mnemonics - Anyone with access to these can steal your funds
  2. Store mnemonics securely - Write them down offline and keep in a safe place
  3. Use testnet for development - Always test on testnet before using mainnet
  4. Verify addresses - Double-check addresses before sending funds
  5. Be cautious with fees - Set appropriate fee rates to avoid overpaying

Network Derivation Paths (BIP86)

  • Mainnet: m/86'/0'/0'/0/0
  • Testnet: m/86'/1'/0'/0/0

The derivation path format is: m/86'/<coin_type>'/<account>'/<change>/<address_index>

Examples

Check out the examples directory for more usage examples:

Requirements

  • Node.js >= 16.0.0
  • Bitcoin Core (optional, for broadcasting transactions)

Dependencies

  • bitcoinjs-lib - Bitcoin library
  • @bitcoinerlab/secp256k1 - Schnorr signatures
  • bip32 - HD key derivation
  • bip39 - Mnemonic generation
  • ecpair - Key pair utilities

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT License - see the LICENSE file for details

Resources

Support

If you find this library helpful, please give it a ⭐️ on GitHub!


Made with ❤️ for the Bitcoin community