sigmastate-js

0.4.0 • Public • Published

CI

ErgoScript compiler and ErgoTree interpreter

This repository contains implementations of ErgoScript compiler and ErgoTree Interpreter for a family of Sigma-protocol based authentication languages (or simply Sigma language).

This JS package is cross-compiled from Scala implementation using Scala.js compiler.

The modules published here can be used directly from JavaScript.

Getting Started

Run following command to add Sigma.JS as a project dependency:

npm install sigmastate-js

Package organization

All classes of this package are separated into several modules (which can also be thought as layers). Each module contains a subset of all the class exported to JavaScript. You can decide which modules to import in your application depending on which classes from this package you want to use. Each subsequent module contains all the classes from the previous modules and some new classes thus forming a layering of modules.

See TypeScript definitions for the list of all exported classes, methods and documentation.

NOTE, you only need to import only one of the modules, the one which contains all the classes you need. This will allow optimizing the size of the final bundle.

The modules are compiled from Scala classes, which are exported to JavaScript (here is an example). The Scala declarations correspond to the TypeScript definitions. Each exported type have two parts: the first part is a Scala class, the second part is a companion object. In Scala the companion object is used to declare static methods and has the same name as the corresponding class. In TypeScript the companion object is exported with $ suffix, thus if X is the JS class, then X$ is the JS object, which corresponds to X.

The list of modules and their exported classes

Examples

How to create Sigma type descriptors

Import Type$ module, then use its fields to access pre-defined descriptors of simple types (e.g. Type$.Int).

Use factory methods like Type$.pairType to create more complex type descriptors. For example,Type$.pairType(Type$.Int, Type$.Long) will create a descriptor of a pair of Int and Long types (Int, Long).

See also examples in tests Type.spec.js

How to create Sigma values

Import Value$ module, then use its factory methods. See examples in tests Value.spec.js

How to work with ErgoTree

Import ErgoTree$ module, and ErgoTree class then use its methods. See examples in tests ErgoTree.spec.js

Compile ErgoScript to ErgoTree

Import SigmaCompiler$ module and SigmaCompiler class, then use its methods. See compiler tests in SigmaCompiler.spec.js

Other examples

See tests in tests/js folder.

Readme

Keywords

none

Package Sidebar

Install

npm i sigmastate-js

Weekly Downloads

29

Version

0.4.0

License

MIT

Unpacked Size

12.6 MB

Total Files

4

Last publish

Collaborators

  • ergomorphic