GithubHelp home page GithubHelp logo

chia-network / node-clvm-lib Goto Github PK

View Code? Open in Web Editor NEW
12.0 22.0 5.0 348 KB

A browser friendly implementation of clvm in TypeScript.

License: Apache License 2.0

TypeScript 100.00%
typescript virtual-machine lisp cryptography chia-blockchain

node-clvm-lib's Introduction

CLVM

npm package

A browser friendly implementation of CLVM in TypeScript, based off of the Chia Network implementation written in Python.

Introduction

Chialisp is an on-chain smart coin programming language developed by the Chia Network. It is compiled and then executed by the Chialisp Virtual Machine, or CLVM for short.

This particular implementation is written with TypeScript, and is not bindings to native code. This allows it to be used in the browser as well. However, if you prefer native bindings, you should check out this library instead.

Usage

You can learn more about how this language works here. This is a implementation and should work as expected, but in any case that it differs, please open an issue.

By design, the functions and methods exposed by this library are synchronous and everything is exported for ease of use.

Since it is written in TypeScript, there are built-in typings for IntelliSense. The following documentation is non-exhaustive, but should be enough for most uses.

Documentation

Value

Either Cons or Uint8Array.

Cons

A tuple of Program and Program.

Program

This represents a program or value in Chialisp or compiled clvm. It is the main class of the library, allowing you to manipulate programs and convert between various forms.

static true

  • A program representing the value 1.

static false

  • A program representing the value ().

atom

  • The Uint8Array value of the program.

cons

  • The Cons pair of the program.

first

  • The first Program value of cons.

rest

  • The rest Program value of cons.

isAtom

  • A boolean for if it's an atom.

isCons

  • A boolean for if it's a cons pair.

isNull

  • A boolean for if it's null.

static cons(first, rest)

  • first is a Program.
  • rest is a Program.
  • Returns a Program that is a cons pair between them.

static fromBytes(bytes)

  • bytes is a Uint8Array.
  • Returns a Program.

static fromHex(hex)

  • hex is a hex string.
  • Returns a Program.

static fromBool(value)

  • value is a boolean.
  • Returns a Program.

static fromInt(value)

  • value is a number.
  • Returns a Program.

static fromBigint(value)

  • value is a bigint.
  • Returns a Program.

static fromText(text)

  • text is a string.
  • Returns a Program.

static fromSource(source)

  • source is a string.
  • Returns a Program.

static fromList(programs)

  • programs is an Array<Program>.
  • Returns a Program.

static deserialize(bytes)

  • bytes is a Uint8Array.
  • Returns a Program.

constructor(value)

  • value is a Value.

positionSuffix

  • A string containing the line and column suffix, if there is one.

at(position)

  • position is a Position.
  • Returns this.

curry(args)

  • args is an Array<Program>.
  • Returns a Program containing the current one with each argument applied to it in reverse, precommitting them in the final solution.

uncurry()

  • Returns a [Program, Array<Program>] containing the mod and curried in arguments.

hash()

  • Returns a Uint8Array of the tree hash of the program. Hashed with 1 for atoms, and 2 for cons pairs.

hashHex()

  • Returns a hex string representation of the tree hash.

define(program)

  • Returns a Program containing the current one wrapped in a mod if there isn't already, and with a definition inserted.

defineAll(programs)

  • programs is an Array<Program>.
  • Returns a Program containing the current one and each definition.

compile(options?)

  • options is a partial CompileOptions, defaulting to strict = false, operators = base, and includeFilePaths = {}.
  • Returns a ProgramOutput that is the result of compiling the program. Should be identical to the run CLI tool.

run(environment, options?)

  • environment is a Program.
  • options is a partial RunOptions, defaulting to strict = false and operators = base.
  • Returns a ProgramOutput that is the result of running the program. Should be identical to the brun CLI tool.

toBytes()

  • Returns a Uint8Array representation.

toHex()

  • Returns a hex string representation.

toBool()

  • Returns a boolean representation.

toInt()

  • Returns a number representation.

toBigInt()

  • Returns a bigint representation.

toText()

  • Returns a string representation.

toSource(showKeywords?)

  • showKeywords is a boolean, by default true.
  • Returns a string source code representation, like it would be if it were an output from run or brun.

toList(strict?)

  • strict is a boolean, by default false.
  • Returns an Array<Program> representation. If it's strict, it must be a proper list.

serialize()

  • Returns a Uint8Array serialized form of the program.

serializeHex()

  • Returns a hex string representation of the serialized form of the program.

equals(value)

  • value is a Program.
  • Returns a boolean for if the values are exactly equal.

toString()

  • Returns a string source code representation, like it would be if it were an output from run or brun.

node-clvm-lib's People

Contributors

dependabot[bot] avatar rigidity avatar wallentx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.