Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tree template types #895

Merged
merged 2 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions sigma-js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,22 @@ The modules published here can be used directly from JavaScript.

# Getting Started

Add the following dependency to your `package.json`:

```json
{
"dependencies": {
"sigmastate-js": "0.1.1"
}
}
Run following command to add Sigma.JS as a project dependency:

```bash
npm install sigmastate-js
```
Then run `npm install`.

# Examples

### How to create Sigma type descriptors

Import `TypeObj` module, then use:

- fields to create simple types (e.g. `TypeObj.Int`)
- method `TypeObj.pairType` (e.g. `TypeObj.pairType(TypeObj.Int, TypeObj.Long)`)
- method `TypeObj.collType` (e.g. `TypeObj.collType(TypeObj.Int)`)

See examples in tests [Type.spec.js](https://github.com/ScorexFoundation/sigmastate-interpreter/blob/933acd7a3753725c8b41994c2126a20279b6809b/sigma-js/tests/js/Type.spec.js)

### How to create Sigma values
Expand All @@ -51,4 +47,3 @@ See examples in tests [ErgoTree.spec.js](https://github.com/ScorexFoundation/sig

Import `SigmaCompilerObj` module and `SigmaCompiler` class, then use its methods.
See compiler tests in [SigmaCompiler.spec.js](https://github.com/ScorexFoundation/sigmastate-interpreter/blob/933acd7a3753725c8b41994c2126a20279b6809b/sigma-js/tests/js/SigmaCompiler.spec.js)

7 changes: 4 additions & 3 deletions sigma-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@
"name": "sigmastate-js",
"version": "0.2.1",
"description": "Sigma.js library",
"main": "dist/main.js",
"files": [
"dist/",
"sigmastate-js.d.ts",
"README.md"
],
"types": "./sigmastate-js.d.ts",
"exports": {
"./internal-*": null,
"./*": "./dist/*.js"
"./main": {
"types": "./sigmastate-js.d.ts",
"default": "./dist/main.js"
}
},
"license": "MIT",
"publishConfig": {
Expand Down
21 changes: 12 additions & 9 deletions sigma-js/sigmastate-js.d.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
declare module "sigmastate-js/main" {
type SigmaCompilerNamedConstantsMap = { [key: string]: Value };
type HexString = string;
type ByteArray = { u: Int8Array };

class ErgoTree {
export declare class ErgoTree {
toHex(): HexString;
bytes(): { u: Uint8Array };
bytes(): ByteArray;
header(): number;
version(): number;
isConstantSegregation(): boolean;
hasSize(): boolean;
constants(): Value[];
template(): ByteArray;
templateHex(): HexString;
toString(): string;
}

class ErgoTreeObj {
export declare class ErgoTreeObj {
static fromHex(value: HexString): ErgoTree;
}

class Type {
export declare class Type {
name: string;
toString(): string;
}

class TypeObj {
export declare class TypeObj {
static Byte: Type;
static Short: Type;
static Int: Type;
Expand All @@ -40,13 +43,13 @@ declare module "sigmastate-js/main" {
static collType(elemType: Type): Type;
}

class Value<T = unknown> {
export declare class Value<T = unknown> {
data: T;
tpe: Type;
toHex(): HexString;
}

class ValueObj {
export declare class ValueObj {
static ofByte(value: number): Value<number>;
static ofShort(value: number): Value<number>;
static ofInt(value: number): Value<number>;
Expand All @@ -57,7 +60,7 @@ declare module "sigmastate-js/main" {
static fromHex<T>(hex: HexString): Value<T>;
}

class SigmaCompiler {
export declare class SigmaCompiler {
compile(
namedConstants: SigmaCompilerNamedConstantsMap,
segregateConstants: boolean,
Expand All @@ -66,7 +69,7 @@ declare module "sigmastate-js/main" {
): ErgoTree;
}

class SigmaCompilerObj {
export declare class SigmaCompilerObj {
static forMainnet(): SigmaCompiler;
static forTestnet(): SigmaCompiler;
}
Expand Down
Loading