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 🙏

© 2024 – Pkg Stats / Ryan Hefner

bitcoin-merkle-proof

v0.1.0

Published

Build and verify Bitcoin Merkle proofs

Downloads

170

Readme

bitcoin-merkle-proof

npm version Build Status Dependency Status

Verify Bitcoin Merkle trees

Bitcoin BIP37 adds support for merkleblock messages, which allow clients to download blocks that only include transactions relevant to them. The transactions are selected via a Bloom Filter.

This module creates and verifies the Merkle proofs in a merkleblock message, and lists the included transactions which match the filter.

Usage

npm install bitcoin-merkle-proof

var bmp = require('bitcoin-merkle-proof')

// build merkle proof object (block #681135 in testnet)
var merkleProof = bmp.build({
  hashes: [
    new Buffer('52a893ef120d5e24aa38604ead9ada6628eea417df6d6096ef0dd7b73a89c0e9', 'hex'),
    new Buffer('a76a1e1bffbbb254bd897e379298549eb8ff4aa57a4bb4c06637b36d76833207', 'hex'),
    new Buffer('056b4e64697677788744a8ad23cc407cbc1c357ff889d9975edd431fb779466f', 'hex'),
    new Buffer('3c51bfb4f9cdd2b8e3a5c47cb1b3bdbc8879a1c1b238d4123dcb572a00b2b80e', 'hex'),
    new Buffer('d6d1f9ca0a4017050379a82ecccb050cf4218f2180087e9592110972a71e375c', 'hex')
  ],
  include: [
    new Buffer('3c51bfb4f9cdd2b8e3a5c47cb1b3bdbc8879a1c1b238d4123dcb572a00b2b80e', 'hex'),
    new Buffer('d6d1f9ca0a4017050379a82ecccb050cf4218f2180087e9592110972a71e375c', 'hex')
  ]
})
// { flags: [ 235, 1 ],
//   hashes:
//    [ <Buffer 19 d6 5e 9e 20 d4 55 db ae 6d 11 39 66 54 7a 1d 41 91 e3 cf eb 3c 4c 2a b9 0e d2 79 5f 39 c4 cc>,
//      <Buffer 05 6b 4e 64 69 76 77 78 87 44 a8 ad 23 cc 40 7c bc 1c 35 7f f8 89 d9 97 5e dd 43 1f b7 79 46 6f>,
//      <Buffer 3c 51 bf b4 f9 cd d2 b8 e3 a5 c4 7c b1 b3 bd bc 88 79 a1 c1 b2 38 d4 12 3d cb 57 2a 00 b2 b8 0e>,
//      <Buffer d6 d1 f9 ca 0a 40 17 05 03 79 a8 2e cc cb 05 0c f4 21 8f 21 80 08 7e 95 92 11 09 72 a7 1e 37 5c> ],
//   numTransactions: 5,
//   merkleRoot: <Buffer b9 b4 50 02 94 c1 84 87 dc 32 a9 29 b5 87 47 5f bf 96 52 be b7 d7 30 10 ea 37 ee 04 83 e5 2e 58> }

// verify proof and return matched tx hashes
var hashes = bmp.verify(merkleProof)
console.log('Matched transactions: ', hashes)
var merkleProof = bmp.build(block)

Construct proof object for transactions. Proof object:

{
  flags: number[],
  hashes: Buffer[],
  numTransactions: number,
  merkleRoot: Buffer
}
var hashes = bmp.verify(merkleProof)

Verifies a Merkle proof object. An error will be thrown if the tree is not valid or does not match the expected Merkle root. Returns an array of txids (as Buffers) which matched the Bloom filter.