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-verifier-ses

v0.3.0

Published

Secure Ecmascript Bitcoin SPV Proofs

Downloads

4

Readme

bitcoin verifier ses

Verify Bitcoin SPV Proofs in SES

Getting Started

Node.js version 10 or greater is required.

  • git clone https://github.com/summa-tx/bitcoin-verifier-ses.git
  • cd bitcoin-verifier-ses
  • npm install

Library Interface

The SPVProof object follows the format found in @summa-tx/bitcoin-spv-js:

/**
 * @typedef {Object} Header
 * @property {Uint8Array}    raw The bitcoin header
 * @property {Uint8Array}    hash The hash of the header
 * @property {Number}        height The height
 * @property {Uint8Array}    merkle_root The merkle root of the header
 * @property {Uint8Array}    prevhash The hash of the previous header
 */

/**
 * @typedef {Object} Proof
 * @property {Uint8Array}    version The version
 * @property {Uint8Array}    vin The vin
 * @property {Uint8Array}    vout The vout
 * @property {Uint8Array}    locktime The locktime
 * @property {Uint8Array}    tx_id The tx ID
 * @property {Number}        index The index
 * @property {Uint8Array}    intermediate_nodes The intermediate nodes
 * @property {Header}        confirming_header The bitcoin header
 */

The Verifier object is defined in lib/primitives.

The Verifier composes predicate functions. These functions can be found in the lib/predicates directory. Each predicate function accepts two arguments, an untrusted proof object and an endowments object, which is set when constructing the Verifier.

When a Verifier object is constructed, it accepts an object with a list of predicates and an endowments object. The predicates are applied in the order in which they appear in the list. Each predicate is passed data from the endowments object if the function name matches the key in the endowments object. If the value in the endowments object is an array, then the predicate will be applied with each object in that array, otherwise it will be applied with the value.

Note: You must pass through an endowments object, even if the predicate(s) does not require it.

Usage

const { Verifier } = require('@summa-tx/bitcoin-verifier-ses');
const { BcoinClient } = require('@summa-tx/bitcoin-spv-js-clients');
const {
  isValidHeaderChain,
  isEnoughWork,
  isCorrectRecipient,
  isValidHeaderChain,
  consumesUTXO
} = require('@summa-tx/bitcoin-verifier-ses/predicates');

// set up a verifier object
// each predicate is a function that must evaluate
// to true for the proof to evaluate to true
// each predicate is passed an untrusted proof object
// and the endowments object
const verifier = new Verifier({
  predicates: [
    isValidHeaderChain,
    isEnoughWork,
    isCorrectRecipient,
    isValidHeaderChain,
    consumesUTXO
  ],
  endowments: {
    isEnoughWork: {
      nwork: /* <big endian hex string or BigInt> */
    },
    isCorrectRecipient: {
      outputScript: /* <Uint8Array> */,
      outputIndex: /* <Number> */
    },
    consumesUTXO: {
      inputIndex: /* <Number> */,
      prevout: {
        hash: /* <Uint8Array> */,
        index: /* <Number> */
      }
    }
  }
});

// the Verifier is an EventEmitter
verifier.on('valid', async (proof) => {
  // react to valid proof here
});

verifier.on('invalid', async (proof) => {
  // react to invalid proof here
});

// see bcoin docs for config options
const client = new BcoinClient({});
const txid = '2f8a31d9b288cc27bcffb44d6de3dc3a8b77a45cbf481c129c86f4d4c';

// fetch proof
const proof = await client.getProof(txid);

// verify the proof
const [valid, reason] = verifier.verify(proof);

if (!valid) {
  throw new Error(reason);
}

CLI Tools

./bin/proof --http-host <http-host> --api-key <apikey> --txid <txid>

Tooling

Bitcoin SPV

Bcoin

Dependencies

This software is based on bcoin.

This software is licensed under the MIT License.

Copyright (c) 2014-2015, Fedor Indutny (https://github.com/indutny)
Copyright (c) 2014-2019, Christopher Jeffrey (https://github.com/chjj)
Copyright (c) 2014-2020, Bcoin Contributors (https://github.com/bcoin-org)