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

chainpoint-validate

v2.3.1

Published

A Node.js module for validating Chainpoint blockchain receipts

Downloads

35

Readme

chainpoint-validate-js

npm npm

A Node.js module for validating Chainpoint blockchain receipts

Installation

$ npm install --save chainpoint-validate

Usage

Use the isValidReceipt function to validate your Chainpoint receipt.

chainpointValidate.isValidReceipt(receipt, confirmAnchor, callback);
/*
  receipt - the receipt to be validated, as a string or JSON
  confirmAnchor - boolean indicating whether you want to confirm the existence of the anchor at its source. True to confirm that the merkle root is stored at the source specified in the anchor object of the receipt (such as in a bitcoin transaction's OP_RETURN value). Will append an 'exists' value to the anchor object in the results when True. False to validate only the receipt content and proof data. 
  callback - This function should expect an error message as its first parameter, and a result object as its second parameter
*/

Example

var chainpointvalidate = require('chainpoint-validate');

var chainpointValidate = new chainpointvalidate();

var validReceipt = {
 "@context": "https://w3id.org/chainpoint/v2",
 "type": "ChainpointSHA256v2",
 "targetHash": "bdf8c9bdf076d6aff0292a1c9448691d2ae283f2ce41b045355e2c8cb8e85ef2",
 "merkleRoot": "51296468ea48ddbcc546abb85b935c73058fd8acdb0b953da6aa1ae966581a7a",
 "proof": [
   {
     "left": "bdf8c9bdf076d6aff0292a1c9448691d2ae283f2ce41b045355e2c8cb8e85ef2"
   },
   {
     "left": "cb0dbbedb5ec5363e39be9fc43f56f321e1572cfcf304d26fc67cb6ea2e49faf"
   },
   {
     "right": "cb0dbbedb5ec5363e39be9fc43f56f321e1572cfcf304d26fc67cb6ea2e49faf"
   }
 ],
 "anchors": [
   {
     "type": "BTCOpReturn",
     "sourceId": "f3be82fe1b5d8f18e009cb9a491781289d2e01678311fe2b2e4e84381aafadee"
   }
 ]
};
var invalidReceipt = "not a receipt";

chainpointValidate.isValidReceipt(validReceipt, true, function (err, result) {
  if(err) {
    // handle this error
  } else {
    // result.isValid will equal true
    // result.anchors will be an array of anchor objects, optionally including
    // an exists parameter, if you configured validation to confirm the anchor as well
  }
});

chainpointValidate.isValidReceipt(invalidReceipt, true, function (err, result) {
  if(err) {
    // handle this error
  } else {
    // result.isValid will equal false
    // result.error will contain a reason why the receipt failed validation
  }
});
Sample Valid Result
{
  isValid: true,
  anchors: [
    {
      type: 'BTCOpReturn',
      sourceId: 'f3be82fe1b5d8f18e009cb9a491781289d2e01678311fe2b2e4e84381aafadee',
      exists: true
    }
  ]
}

When 'confirmAnchor' is set to true, an additional 'exists' value is added indicating the whether or not the data actually exists in the transaction. This function relies on BlockCypher's API which currently rate limits to 3 per second and 200 per hour. Confirmations requested beyond those limits will return false.

Sample Invalid Result
{
  isValid: false,
  error: 'Cannot parse receipt JSON'
}