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.
Run following command to add Sigma.JS as a project dependency:
npm install sigmastate-js
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.
-
sigma-core module - contains core classes of Sigma.js library
-
sigma-data module - contains classes for working with ErgoTree, addresses and all related serializers
-
sigma-interpreter module - contains classes for proving sigma proposition and their verification
- all classes from sigma-data module
- ProverHints
- ProverSecret
- SigmaPropProver
- SigmaPropVerifier
-
sigma-sdk module - contains classes for reducing and signing transactions
- all classes from sigma-interpreter module
- BlockchainParameters
- BlockchainStateContext
- ContractTemplate
- Header
- PreHeader
- ProverBuilder
- ReducedTransaction
- SigmaProver
-
sigma-compiler module - contains classes for working with ErgoScript compiler
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
Import Value$
module, then use its factory methods.
See examples in tests Value.spec.js
Import ErgoTree$
module, and ErgoTree
class then use its methods.
See examples in tests ErgoTree.spec.js
Import SigmaCompiler$
module and SigmaCompiler
class, then use its methods.
See compiler tests in SigmaCompiler.spec.js
See tests in tests/js folder.