@indigocore/cs-validator

0.3.0 • Public • Published

MapExplorer Core

Library for validating chainscript objects

npm

Installation

Browser

<!-- Polyfill for browser compatibility -->
<script src="https://libs.stratumn.com/babel-polyfill.min.js"></script>
<!-- Actual Library -->
<script src="https://libs.stratumn.com/cs-validator.js"></script>

If you want a specific version, include https://libs.stratumn.com/cs-validator{version}.js instead (for instance https://libs.stratumn.com/cs-validator-0.1.0.js).

Node.js

$ npm install @indigocore/cs-validator
var StratumnCsValidator = require('@indigocore/cs-validator');

// or using es6
import { MapValidator, SegmentValidator } from '@indigocore/cs-validator';

Usage

Validate a chainscript

new StratumnCsValidator.MapValidator(JSON.parse(chainscript)).validate()

Returns a Promise that resolves to an error object such as:

{
      linkHash: [Promise, ...],
      stateHash: [Promise, ...],
      merklePath: [Promise, ...],
      fossil: [Promise, ...]
}

Each promise, in each array of each category resolves to an error string if an inconsistency has been detected. It resolves to null otherwise.

Errors can be retrieved with (for instance):

Promise.all(errors.linkHash).
  then(err => err.filter(Boolean));

Development

Install dependencies:

$ npm install

Build:

$ npm run build

Test:

$ npm test

The integration tests use a build version of the library. Make sure you've run npm run build if you want your changes to be taken into account.

Package Sidebar

Install

npm i @indigocore/cs-validator

Weekly Downloads

4

Version

0.3.0

License

Apache-2.0

Unpacked Size

279 kB

Total Files

25

Last publish

Collaborators

  • alexppxela
  • simonvadee
  • t-bast
  • bejito
  • sf-stratumn
  • conord33
  • jeremie-stratumn
  • piedup