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

@summa-tx/bitcoin-spv-js-clients

v0.1.4

Published

Clients for fetching bitcoin SPV proofs in Javascript

Downloads

1

Readme

bitcoin-spv proof fetcher

The following clients are provided to fetch Bitcoin data to create proofs.

Clients

  • BcoinClient

BcoinClient

Use the BcoinClient fetch Bitcoin data from a bcoin node. See the bcoin docs for how to run your own node.

Install

Node.js:

$ npm i --save @summa-tx/bitcoin-spv-js-clients
const { BcoinClient } = require('@summa-tx/bitcoin-spv-js-clients');

ES6 module:

import { BcoinClient } from '@summa-tx/bitcoin-spv-js-clients';

Use

The BcoinClient proof fetcher exports a single constructor function, BcoinClient, which accepts an options Object to configure the client. This constructor is an extension of bcoin's NodeClient. See bcoin.io for more information about how to configure the client.

const options = {
  network: 'testnet',
  port: 18332,
  apiKey: 'api-key'
};

const client = new BcoinClient(options);

Methods

client.getBlockHeader(block)

  • @param {Hash|Number} block
  • @returns {Promise}

Retrieve a block header.

const client = new BcoinClient(options);
const blockHeader = await client.getBlockHeader(150151);

// block header
// {
//   "hash": "6f1003edd05cad861395225415160b5236968cc223fe982796b6e959c9651d44",
//   "version": 536870912,
//   "prevBlock": "0c4ea5e675941eca1909275f21903cef755069a03c57c10f4d4dadcdd7146daf",
//   "merkleRoot": "9a249c682aba07943c8a1f9bd774a15d71372fcd7f3f9ee99e8c7aa022ae6aa0",
//   "time": 1571661863,
//   "bits": 545259519,
//   "nonce": 8,
//   "height": 100,
//   "chainwork": "00000000000000000000000000000000000000000000000000000000000000ca"
// }

client.getProof(txid)

  • @param {String} txid - txid in big endian
  • @returns {Object} - proof object

Get a proof for a transaction.

const client = new BcoinClient(options);
const txid =

// proof object
// {
//   version: {String},
//   vin: {String},
//   vout: {String},
//   locktime: {String},
//   tx_id: {String},
//   index: {Number},
//   confirming_header: {Object},
//   intermediate_nodes: {String}
// }

client.getHeader(block)

  • @param {Hash|Number} block - block height or hash
  • @returns {Object} header - header object

Gets header by height or hash.

const client = new BcoinClient(options);
const block = 12345;
const header = client.getHeader(block);

// {
//   raw: {String},
//   hash: {String},
//   height: {Number},
//   prevhash: {String},
//   merkle_root: {String},
// }

client.getMerkleProof(txid, height)

  • @param {String} txid
  • @param {Number} height
  • @returns {[][]String, Number} - a merkle proof and the index of the leaf

Validate the merkle tree of a block and then compute a merkle proof of inclusion for the txid.

const client = new BcoinClient(options);
const height = 12345;
const txid = '3a4324234'
const header = client.getMerkleProof(txid, height);

// merkle proof
// [
//   '8e2d404a039a7a3e1768b161aa23546aab0444b73905bdd3d68b3d6f1769e8c0...',
//   4
// ]

client.getHeaderChainByCount(height, count, enc)

  • @param {Number} height - starting block height
  • @param {Number} count - number of headers
  • @param {String} enc - 'json' or 'hex' or 'btcspv'
  • @returns {Object}

Fetch a header chain by count.

const client = new BcoinClient(options);
const height = 12345;
const numOfHeaders = 2;
const encoding = 'hex';
const header = client.getHeaderChainByCount(height, numOfHeaders, encoding);

// headers (hex)
// {
//   headers: '00000020a15e218f5f158a31053ea101b917a6113c807f6bcdc85a000000000000000000cc7cf9eab23c2eae050377375666cd7862c1dfeb81abd3198c3a3f8e045d91484a39225af6d00018659e5e8a0101000000010000000000000000000000000000000000000000000000000000000000000000ffffffff64030096072cfabe6d6d08d1c2f6d904f4e1cd10c6558f8e5aed5d6a89c43bb22862464ebb819dd8813404000000f09f909f104d696e6564206279206a6f73656d7372000000000000000000000000000000000000000000000000000000000000000000007f06000001807c814a000000001976a914c825a1ecf2a6830c4401620c3a16f1995057c2ab88acefebcf38...'
// }
const header = client.getHeaderChainByCount(height, numOfHeaders, 'json');

// headers (json)
// {
//   headers: [
//     {
//       "hash": "6f1003edd05cad861395225415160b5236968cc223fe982796b6e959c9651d44",
//       "version": 536870912,
//       "prevBlock": "0c4ea5e675941eca1909275f21903cef755069a03c57c10f4d4dadcdd7146daf",
//       "merkleRoot": "9a249c682aba07943c8a1f9bd774a15d71372fcd7f3f9ee99e8c7aa022ae6aa0",
//       "time": 1571661863,
//       "bits": 545259519,
//       "nonce": 8,
//       "height": 100,
//       "chainwork": "00000000000000000000000000000000000000000000000000000000000000ca"
//     },
//         {
//       "hash": "6f1003edd05cad861395225415160b5236968cc223fe982796b6e959c9651d44",
//       "version": 536870912,
//       "prevBlock": "0c4ea5e675941eca1909275f21903cef755069a03c57c10f4d4dadcdd7146daf",
//       "merkleRoot": "9a249c682aba07943c8a1f9bd774a15d71372fcd7f3f9ee99e8c7aa022ae6aa0",
//       "time": 1571661863,
//       "bits": 545259519,
//       "nonce": 8,
//       "height": 100,
//       "chainwork": "00000000000000000000000000000000000000000000000000000000000000ca"
//     },
//   ]
// }