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

bitcoin-tx-proof

v1.0.0

Published

A TypeScript library for generating Bitcoin transaction proofs, including witness data and merkle proofs. This package helps developers verify Bitcoin transactions and their inclusion in blocks, supporting both SegWit and non-SegWit transactions.

Readme

Bitcoin Transaction Proof

A TypeScript library for generating Bitcoin transaction proofs, including witness data and merkle proofs. This package helps developers verify Bitcoin transactions and their inclusion in blocks, supporting both SegWit and non-SegWit transactions.

Features

  • Generate transaction proofs with witness data
  • Calculate merkle proofs for transaction verification
  • Support for both SegWit and non-SegWit transactions
  • Built-in caching and rate limiting for RPC calls
  • Works with any Bitcoin node (local or remote)
  • Full TypeScript support

Installation

npm install bitcoin-tx-proof

Quick Start

import { bitcoinTxProof } from "bitcoin-tx-proof";

// Get proof for a transaction
const proof = await bitcoinTxProof(
  "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b", // txid
  277316, // block height
  {
    url: "http://localhost:8332",
    username: "your_rpc_username", // optional
    password: "your_rpc_password", // optional
  }
);

API Reference

Main Function

bitcoinTxProof(txid, blockHeight, rpcConfig)

Generates a complete transaction proof including witness data.

Parameters:

  • txid: string - The transaction ID to generate proof for
  • blockHeight: number - The block height containing the transaction
  • rpcConfig: BitcoinRPCConfig - Configuration for Bitcoin RPC connection

Returns: Promise

Types:

interface BitcoinRPCConfig {
  url: string;          // Bitcoin RPC endpoint URL
  username?: string;    // Optional RPC username
  password?: string;    // Optional RPC password
}

interface TxProofResult {
  blockHeight: number;          // Height of the block
  transaction: string;          // Raw transaction hex
  blockHeader: string;          // Block header hex
  txIndex: number;             // Index in block
  merkleProofDepth: number;    // Merkle tree depth
  witnessMerkleProof: string;  // Witness merkle proof
  witnessReservedValue: string;// Witness reserved value
  coinbaseTransaction: string; // Coinbase transaction
  coinbaseMerkleProof: string;// Coinbase merkle proof
}

Advanced Usage

Direct RPC Access

import { BitcoinRPC } from 'bitcoin-tx-proof';

const rpc = new BitcoinRPC({
  url: 'http://localhost:8332',
  username: 'rpcuser',
  password: 'rpcpassword'
});

// Make any Bitcoin RPC call
const blockHash = await rpc.call('getblockhash', [500000]);
const block = await rpc.call('getblock', [blockHash]);

Merkle Calculations

import { calculateWTXID, getMerkleProof } from 'bitcoin-tx-proof';

// Calculate witness txid
const wtxid = calculateWTXID(transactionHex);

// Generate merkle proof
const proof = getMerkleProof(txHashes, txIndex);

Error Handling

try {
  const proof = await bitcoinTxProof(txid, blockHeight, rpcConfig);
} catch (error) {
  if (error.message.includes('Invalid transaction ID')) {
    // Handle invalid txid
  } else if (error.message.includes('RPC Error')) {
    // Handle RPC connection issues
  } else if (error.message.includes('Transaction not found')) {
    // Handle missing transaction
  }
}

Performance Features

Caching

  • Built-in caching for RPC calls (10-minute TTL)
  • Automatic cache invalidation
  • Memory-efficient caching strategy

Rate Limiting

  • Automatic rate limiting (10 requests/second)
  • Configurable limits
  • Queue management for concurrent requests

Development

# Install dependencies
npm install

# Run tests
npm test

# Build
npm run build

# Lint
npm run lint

# Format code
npm run format

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

MIT