diff --git a/.dist/npm/CHANGELOG.md b/.dist/npm/CHANGELOG.md deleted file mode 100644 index 65aacf4..0000000 --- a/.dist/npm/CHANGELOG.md +++ /dev/null @@ -1,170 +0,0 @@ -# Changelog - -## [0.0.19] - -**There are 2 breaking changes.** -- Changed `OperatorDict` arguments format. -Past: `OperatorDict(atom_op_function_map, quote_atom, apply_atom, unknown_op_handler)` -New: `OperatorDict(atom_op_function_map, option)` -where `option` is `{quote_atom: Bytes, apply_atom: Bytes, unknown_op_handler: typeof default_unknown_op}` - -- When you initialize `Bytes` using constructor like `new Byte(data)`, `data` is not copied but just stored and keeps reference of `data`, for performance enhancement. -In javascript, byte copy by `TypedArray` constructor is not sufficiently fast. -So I left user an option how to initialize `Bytes` instance. Data copy, or Store reference. -If you want to copy data and cut reference apart, then please get `Bytes` instance by `Bytes.from` factory function. - -**Resolved a deep tree performance issue** -Before this version, `yarn test serialize_test --testNamePattern=test_very_deep_tree` was really slow. It took around 80 seconds to complete test. -At this version, I've managed to improve test complete time to `79s` -> `2s` by pre-allocating buffer memory on `Stream` instance. - -### Changed -- Changed `OperatorDict` arguments format. -- When you initialize `Bytes` using constructor like `new Byte(data)`, `data` is not copied but just stored and keeps reference of `data`, for performance enhancement. -- Greatly improved overall performance by pre-allocating buffer memory on `Stream` instance. -- Improved performance of `Bytes::equal_to`. -- Changed parameter type of `SExp::equal_to` from `CastableType` to `any` -- Replaced use of `instanceof` operator for non-native types. -- Updated bls-signatures version to 0.2.1-beta.1 -- Improved `Bytes::concat` performance. -- Reorganized dist folder -### Fixed -- Fixed an issue where `SExp.to()` did not work the same as python's clvm. -- Fixed an issue where Bytes-SExp comparison like `b('aaa').equal_to(SExp.null())` did not work. -- Fixed an issue where `OperatorDict` did not throw Error when either `quote` or `apply` is not specified. -### Added -- Added `list()` function working similar to Python's `list()`. -- Added `Bytes::repeat` function. - -## [0.0.18] -### Changed -- Fixed an issue where `int_to_bytes` did not work as expected if the argument is a negative number. -- Changed `Bytes::toString()` to return python's `bytes.__repr__` style string. - -## [0.0.17] -### Changed -- Updated `jscrypto` version to 1.0.2 - -## [0.0.16] -### Added -- Added license information to README.md -### Fixed -- Fixed a bug in `sexp_from_stream` -- Fixed incorrect use of `int_to_bytes` - -## [0.0.15] -### Fixed -- Fixed a bug in `pre_build.js` - -## [0.0.14] -### Changed -- Changed new line style for files in `dist/` from windows-style(CR) to linux-style(LF). -### Removed -- Removed `WordArray32` from possible argument of `Bytes.from`. -### Added -- Added `Bytes.SHA256()`. - -## [0.0.13] -### Changed -- `Bytes.from()` now accepts an array of number. -### Fixed -- Fixed an issue where `int_to_bytes` returns value incompatible with clvm in python. -- Fixed a minor issue - -## [0.0.12] -### Fixed -- Don't remove leading '00' or 'ff' when serializing SExp to hex string. -- Fixed an issue where `SExp.to(0)` is converted to `SExp(0x00)` where `SExp(0x80)` is expected. -- Fixed an issue where it raises an Error when executing `Bytes::equal_to(None)`. -- Fixed a minor issue - -## [0.0.11] -### Changed -- Made `EvalError::_sexp` public. - -## [0.0.10] -### Added -- Added `h()` helper function which equals to `Bytes.from(, "hex")` -### Fixed -- Removed type-guard from `SExp::listp()` -- Removed `SExpAsAtom` type and `SExpAsPair` type as they seem not working. - - -## [0.0.9] -### Added -- Added `Bytes::hex()` which is an alias of `Bytes::toString()` -- Added `Bytes::decode()` -- Added `Bytes::startswith()` and `Bytes::endswith()` -- Added `SExpAsAtom` type and `SExpAsPair` type. -- Added hex string support to `b()`. In `b("0xaa", "hex")`, `0xaa` is now parsed as hex string. -### Fixed -- Fixed value of `SExp.TRUE` and `SExp.FALSE` - -## [0.0.8] -### Added -- Added `b()` helper function which equals to `Bytes.from(, "utf8")` -- Added `isTuple`, `isList` functions. - -## [0.0.7] -### Changed -- Made return type of `as_javascript()` explicit -- Updated `CastableType` - -## [0.0.6] -### Fixed -- Fixed an issue where `SExp::as_javascript()` does not return expected value. -- Fixed an issue where `SExp.to()` raises unexpected Error. -- Fixed incorrect function name `__repl__` to `__repr__` -### Changed -- Removed '0x' prefix from results of `SExp::__repr__()` - -## [0.0.5] -### Fixed -- Fixed an issue where `SExp.to()` falls in infinite loop. - -## [0.0.4] -### Changed -- Changed source of `bls-signatures` to `@chiamine/bls-signatures` - - When installing from previous `Chia-Mine/bls-signatures#npm`, the npm module version is too old or unstable. - Sometimes it installed the latest commit and another time installed old cache. - I decided to install the module not from GitHub branch but official npm registry for stability. -- Updated README - -### Fixed -- Fixed various eslint errors - -## [0.0.3] -### Added -- Added `to_sexp_f` export to index.ts/index.js - -## [0.0.2] -### Changed -- Change tuple type `Tuple2` -> `Tuple`. - -## [0.0.1] - 2021-06-16 -### Fixed -- Fixed various bugs - -## [0.0.0] - 2021-06-15 -Initial (beta) release. - - -[0.0.19]: https://github.com/Chia-Mine/clvm-js/compare/v0.0.18...v0.0.19 -[0.0.18]: https://github.com/Chia-Mine/clvm-js/compare/v0.0.17...v0.0.18 -[0.0.17]: https://github.com/Chia-Mine/clvm-js/compare/v0.0.16...v0.0.17 -[0.0.16]: https://github.com/Chia-Mine/clvm-js/compare/v0.0.15...v0.0.16 -[0.0.15]: https://github.com/Chia-Mine/clvm-js/compare/v0.0.14...v0.0.15 -[0.0.14]: https://github.com/Chia-Mine/clvm-js/compare/v0.0.13...v0.0.14 -[0.0.13]: https://github.com/Chia-Mine/clvm-js/compare/v0.0.12...v0.0.13 -[0.0.12]: https://github.com/Chia-Mine/clvm-js/compare/v0.0.11...v0.0.12 -[0.0.11]: https://github.com/Chia-Mine/clvm-js/compare/v0.0.10...v0.0.11 -[0.0.10]: https://github.com/Chia-Mine/clvm-js/compare/v0.0.9...v0.0.10 -[0.0.9]: https://github.com/Chia-Mine/clvm-js/compare/v0.0.8...v0.0.9 -[0.0.8]: https://github.com/Chia-Mine/clvm-js/compare/v0.0.7...v0.0.8 -[0.0.7]: https://github.com/Chia-Mine/clvm-js/compare/v0.0.6...v0.0.7 -[0.0.6]: https://github.com/Chia-Mine/clvm-js/compare/v0.0.5...v0.0.6 -[0.0.5]: https://github.com/Chia-Mine/clvm-js/compare/v0.0.4...v0.0.5 -[0.0.4]: https://github.com/Chia-Mine/clvm-js/compare/v0.0.3...v0.0.4 -[0.0.3]: https://github.com/Chia-Mine/clvm-js/compare/v0.0.2...v0.0.3 -[0.0.2]: https://github.com/Chia-Mine/clvm-js/compare/v0.0.1...v0.0.2 -[0.0.1]: https://github.com/Chia-Mine/clvm-js/compare/v0.0.0...v0.0.1 -[0.0.0]: https://github.com/Chia-Mine/clvm-js/releases/tag/v0.0.0 diff --git a/.dist/npm/CLVMObject.d.ts b/.dist/npm/CLVMObject.d.ts deleted file mode 100644 index 7f3f206..0000000 --- a/.dist/npm/CLVMObject.d.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { None, Optional } from "./__python_types__"; -import { Bytes, Tuple } from "./__type_compatibility__"; -export declare type CLVMType = { - atom: Optional; - pair: Optional>; -}; -export declare type Atom = { - atom: Bytes; - pair: None; -}; -export declare type Cons = { - atom: None; - pair: Tuple; -}; -export declare class CLVMObject implements CLVMType { - atom: Optional; - pair: Optional>; - constructor(v: any); -} -export declare function isAtom(obj: CLVMType): obj is Atom; -export declare function isCons(obj: CLVMType): obj is Cons; -export declare function isCLVMObject(v: any): v is CLVMObject; diff --git a/.dist/npm/CLVMObject.js b/.dist/npm/CLVMObject.js deleted file mode 100644 index 81f15c4..0000000 --- a/.dist/npm/CLVMObject.js +++ /dev/null @@ -1,48 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.isCLVMObject = exports.isCons = exports.isAtom = exports.CLVMObject = void 0; -const __python_types__1 = require("./__python_types__"); -const __type_compatibility__1 = require("./__type_compatibility__"); -const EvalError_1 = require("./EvalError"); -/* - This class implements the CLVM Object protocol in the simplest possible way, - by just having an "atom" and a "pair" field - */ -class CLVMObject { - constructor(v) { - this.atom = __python_types__1.None; - // this is always a 2-tuple of an object implementing the CLVM object protocol. - this.pair = __python_types__1.None; - if (isCLVMObject(v)) { - this.atom = v.atom; - this.pair = v.pair; - } - else if (__type_compatibility__1.isTuple(v)) { - this.pair = v; - this.atom = __python_types__1.None; - } - else { - this.atom = v; - this.pair = __python_types__1.None; - } - } -} -exports.CLVMObject = CLVMObject; -function isAtom(obj) { - if ((obj.atom && obj.pair) || (!obj.atom && !obj.pair)) { - throw new EvalError_1.EvalError("Invalid clvm", obj); - } - return Boolean(obj.atom && !obj.pair); -} -exports.isAtom = isAtom; -function isCons(obj) { - if ((obj.atom && obj.pair) || (!obj.atom && !obj.pair)) { - throw new EvalError_1.EvalError("Invalid clvm", obj); - } - return Boolean((!obj.atom && obj.pair)); -} -exports.isCons = isCons; -function isCLVMObject(v) { - return v && typeof v.atom !== "undefined" && typeof v.pair !== "undefined"; -} -exports.isCLVMObject = isCLVMObject; diff --git a/.dist/npm/EvalError.d.ts b/.dist/npm/EvalError.d.ts deleted file mode 100644 index 0b6ce76..0000000 --- a/.dist/npm/EvalError.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -import type { str } from "./__python_types__"; -import type { CLVMObject } from "./CLVMObject"; -export declare class EvalError extends Error { - _sexp?: CLVMObject; - name: string; - constructor(message: str, sexp: CLVMObject); -} diff --git a/.dist/npm/EvalError.js b/.dist/npm/EvalError.js deleted file mode 100644 index 7117bc0..0000000 --- a/.dist/npm/EvalError.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.EvalError = void 0; -class EvalError extends Error { - constructor(message, sexp) { - super(message); - this.name = "EvalError"; - this._sexp = sexp; - } -} -exports.EvalError = EvalError; diff --git a/.dist/npm/LICENSE b/.dist/npm/LICENSE deleted file mode 100644 index cdc5243..0000000 --- a/.dist/npm/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License - -Copyright (c) 2019 Admin ChiaMineJP - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. \ No newline at end of file diff --git a/.dist/npm/README.md b/.dist/npm/README.md deleted file mode 100644 index 7ee6bf4..0000000 --- a/.dist/npm/README.md +++ /dev/null @@ -1,70 +0,0 @@ -# clvm - -Javascript implementation of CLVM (Chia Lisp VM) -Still Work in progress.(Untested) - -**v0.x.x is test purpose only!** -Please report bugs to https://github.com/Chia-Mine/clvm-js/issues - -## Install -```shell -npm install clvm -# or -yarn add clvm -``` - -## Example -```javascript -// in nodejs context -async function main(){ - var clvm = require("clvm"); - - // 'clvm.initialization()' here is not required - // if you're so sure it never calls 'pubkey_for_exp' or 'point_add' operation. - // When one of those operations is called without prior 'clvm.initialize()' - // it will raise an Error. - // If it is unknown whether 'pubkey_for_exp' or 'point_add' will be called, - // then put 'await clvm.initialize()' for safety. - // I know this 'await clvm.initialize()' makes code asynchronous - // and really impacts on code architecture. - // This is because 'clvm' relys on a wasm of 'bls-signatures', - // which requires asynchronous loading. - await clvm.initialize(); - - const {SExp, OPERATOR_LOOKUP, KEYWORD_TO_ATOM} = clvm; - const v1 = OPERATOR_LOOKUP(KEYWORD_TO_ATOM["+"], SExp.to([3,4,5]))[1]; - const v2 = SExp.to(12); - const ok = v1.equal_to(v2); - console.log(`ok: ${ok}`); // 'ok: true' -} - -main().catch(e => console.error(e)); -``` - -## Use in browser -If you'd like to run some javascript code which depends on `clvm` on browser, -you need to put `blsjs.wasm` to the same directory as the code who loads `clvm`. - -
-├── ...
-├── main.js      # js file which clvm is compiled into
-└── blsjs.wasm   # copy it from npm_modules/clvm/dist/browser/blsjs.wasm
-
- -**Note1**: Don't forget to wait `clvm.initialize()` if you are not sure whether `pubkey_for_exp`/`point_add` will be called. -**Note2**: If you're really sure that `pubkey_for_exp`/`point_add` will never be called, then you can opt out `blsjs.wasm` and `await clvm.initialize()`. -If so, you can make your code fully synchronous. - - - -## clvm license -`clvm-js` is based on [clvm](https://github.com/Chia-Network/clvm) with the -[Apache license 2.0](https://github.com/Chia-Network/clvm/blob/main/LICENSE) - -## bls-signatures license -[bls-signatures](https://github.com/Chia-Network/bls-signatures) is used under the -[Apache license 2.0](https://github.com/Chia-Network/bls-signatures/blob/main/LICENSE) - -## jscrypto license -[jscrypto](https://github.com/Hinaser/jscrypto) is used under the -[MIT license](https://github.com/Hinaser/jscrypto/blob/master/LICENSE) diff --git a/.dist/npm/SExp.d.ts b/.dist/npm/SExp.d.ts deleted file mode 100644 index aa3161b..0000000 --- a/.dist/npm/SExp.d.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { G1Element } from "@chiamine/bls-signatures"; -import { int, None, Optional, str } from "./__python_types__"; -import { CLVMObject, CLVMType } from "./CLVMObject"; -import { Bytes, Tuple } from "./__type_compatibility__"; -export declare type CastableType = SExp | CLVMType | Bytes | str | int | None | G1Element | CastableType[] | Tuple; -export declare function looks_like_clvm_object(o: any): o is CLVMObject; -export declare function convert_atom_to_bytes(v: any): Bytes; -export declare function to_sexp_type(value: CastableType): CLVMObject; -export declare class SExp implements CLVMType { - atom: Optional; - pair: Optional>; - static readonly TRUE: SExp; - static readonly FALSE: SExp; - static readonly __NULL__: SExp; - static to(v: CastableType): SExp; - static null(): SExp; - constructor(v: CLVMObject); - as_pair(): Tuple | None; - listp(): boolean; - nullp(): boolean; - as_int(): number; - as_bin(): Bytes; - cons(right: any): SExp; - first(): SExp; - rest(): SExp; - as_iter(): Generator; - equal_to(other: any): boolean; - list_len(): number; - as_javascript(): import("./as_javascript").TToJavascript; - toString(): string; - __repr__(): string; -} -export declare function isSExp(v: any): v is SExp; diff --git a/.dist/npm/SExp.js b/.dist/npm/SExp.js deleted file mode 100644 index c45e514..0000000 --- a/.dist/npm/SExp.js +++ /dev/null @@ -1,257 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.isSExp = exports.SExp = exports.to_sexp_type = exports.convert_atom_to_bytes = exports.looks_like_clvm_object = void 0; -const __python_types__1 = require("./__python_types__"); -const CLVMObject_1 = require("./CLVMObject"); -const __type_compatibility__1 = require("./__type_compatibility__"); -const casts_1 = require("./casts"); -const serialize_1 = require("./serialize"); -const as_javascript_1 = require("./as_javascript"); -const EvalError_1 = require("./EvalError"); -function looks_like_clvm_object(o) { - if (!o || typeof o !== "object") { - return false; - } - return Boolean("atom" in o && "pair" in o); -} -exports.looks_like_clvm_object = looks_like_clvm_object; -// this function recognizes some common types and turns them into plain bytes -function convert_atom_to_bytes(v) { - if (__type_compatibility__1.isBytes(v)) { - return v; - } - else if (typeof v === "string") { - return __type_compatibility__1.Bytes.from(v, "utf8"); - } - else if (typeof v === "number") { - return casts_1.int_to_bytes(v); - } - else if (typeof v === "boolean") { // Tips. In Python, isinstance(True, int) == True. - return casts_1.int_to_bytes(v ? 1 : 0); - } - else if (v === __python_types__1.None || !v) { - return __type_compatibility__1.Bytes.NULL; - } - else if (__type_compatibility__1.isIterable(v)) { - if (v.length > 0) { - throw new Error(`can't cast ${JSON.stringify(v)} to bytes`); - } - return __type_compatibility__1.Bytes.NULL; - } - else if (typeof v.serialize === "function") { - return __type_compatibility__1.Bytes.from(v, "G1Element"); - } - throw new Error(`can't cast ${JSON.stringify(v)} to bytes`); -} -exports.convert_atom_to_bytes = convert_atom_to_bytes; -const op_convert = 0; -const op_set_left = 1; -const op_set_right = 2; -const op_prepend_list = 3; -function to_sexp_type(value) { - let v = value; - const stack = [v]; - const ops = [__type_compatibility__1.t(0, __python_types__1.None)]; - while (ops.length) { - const item = ops.pop(); - const op = item[0]; - let targetIndex = item[1]; - // convert value - if (op === op_convert) { - if (looks_like_clvm_object(stack[stack.length - 1])) { - continue; - } - v = stack.pop(); - if (__type_compatibility__1.isTuple(v)) { - if (v.length !== 2) { - throw new Error(`can't cast tuple of size ${v.length}`); - } - const [left, right] = v; - targetIndex = stack.length; - stack.push(new CLVMObject_1.CLVMObject(__type_compatibility__1.t(left, right))); - if (!looks_like_clvm_object(right)) { - stack.push(right); - ops.push(__type_compatibility__1.t(2, targetIndex)); // set right - ops.push(__type_compatibility__1.t(0, __python_types__1.None)); // convert - } - if (!looks_like_clvm_object(left)) { - stack.push(left); - ops.push(__type_compatibility__1.t(1, targetIndex)); - ops.push(__type_compatibility__1.t(0, __python_types__1.None)); - } - continue; - } - else if (Array.isArray(v) /* && !(v instance of Tuple) */) { - targetIndex = stack.length; - stack.push(new CLVMObject_1.CLVMObject(__type_compatibility__1.Bytes.NULL)); - for (const _ of v) { - stack.push(_); - ops.push(__type_compatibility__1.t(3, targetIndex)); // prepend list - // we only need to convert if it's not already the right type - if (!looks_like_clvm_object(_)) { - ops.push(__type_compatibility__1.t(0, __python_types__1.None)); // convert - } - } - continue; - } - stack.push(new CLVMObject_1.CLVMObject(convert_atom_to_bytes(v))); - continue; - } - if (targetIndex === null) { - throw new Error("Invalid target. target is null"); - } - if (op === op_set_left) { // set left - stack[targetIndex].pair = __type_compatibility__1.t(new CLVMObject_1.CLVMObject(stack.pop()), stack[targetIndex].pair[1]); - } - else if (op === op_set_right) { // set right - stack[targetIndex].pair = __type_compatibility__1.t(stack[targetIndex].pair[0], new CLVMObject_1.CLVMObject(stack.pop())); - } - else if (op === op_prepend_list) { // prepend list - stack[targetIndex] = new CLVMObject_1.CLVMObject(__type_compatibility__1.t(stack.pop(), stack[targetIndex])); - } - } - // there's exactly one item left at this point - if (stack.length !== 1) { - throw new Error("internal error"); - } - // stack[0] implements the clvm object protocol and can be wrapped by an SExp - return stack[0]; -} -exports.to_sexp_type = to_sexp_type; -/* - SExp provides higher level API on top of any object implementing the CLVM - object protocol. - The tree of values is not a tree of SExp objects, it's a tree of CLVMObject - like objects. SExp simply wraps them to privide a uniform view of any - underlying conforming tree structure. - - The CLVM object protocol (concept) exposes two attributes: - 1. "atom" which is either None or bytes - 2. "pair" which is either None or a tuple of exactly two elements. Both - elements implementing the CLVM object protocol. - Exactly one of "atom" and "pair" must be None. - */ -class SExp { - constructor(v) { - this.atom = __python_types__1.None; - // this is always a 2-tuple of an object implementing the CLVM object protocol. - this.pair = __python_types__1.None; - this.atom = v.atom; - this.pair = v.pair; - } - static to(v) { - if (isSExp(v)) { - return v; - } - if (looks_like_clvm_object(v)) { - return new SExp(v); - } - // this will lazily convert elements - return new SExp(to_sexp_type(v)); - } - static null() { - return SExp.__NULL__; - } - as_pair() { - const pair = this.pair; - if (pair === __python_types__1.None) { - return pair; - } - return __type_compatibility__1.t(new SExp(pair[0]), new SExp(pair[1])); - } - listp() { - return this.pair !== __python_types__1.None; - } - nullp() { - return this.atom !== __python_types__1.None && this.atom.raw().length === 0; - } - as_int() { - return casts_1.int_from_bytes(this.atom); - } - as_bin() { - const f = new __type_compatibility__1.Stream(); - serialize_1.sexp_to_stream(this, f); - return f.getValue(); - } - cons(right) { - return SExp.to(__type_compatibility__1.t(this, right)); - } - first() { - const pair = this.pair; - if (pair) { - return new SExp(pair[0]); - } - throw new EvalError_1.EvalError("first of non-cons", this); - } - rest() { - const pair = this.pair; - if (pair) { - return new SExp(pair[1]); - } - throw new EvalError_1.EvalError("rest of non-cons", this); - } - *as_iter() { - let v = this; - while (!v.nullp()) { - yield v.first(); - v = v.rest(); - } - } - equal_to(other /* CastableType */) { - try { - other = SExp.to(other); - const to_compare_stack = [__type_compatibility__1.t(this, other)]; - while (to_compare_stack.length) { - const [s1, s2] = to_compare_stack.pop(); - const p1 = s1.as_pair(); - if (p1) { - const p2 = s2.as_pair(); - if (p2) { - to_compare_stack.push(__type_compatibility__1.t(p1[0], p2[0])); - to_compare_stack.push(__type_compatibility__1.t(p1[1], p2[1])); - } - else { - return false; - } - } - else if (s2.as_pair() || !(s1.atom && s2.atom && s1.atom.equal_to(s2.atom))) { - return false; - } - } - return true; - } - catch (e) { - return false; - } - } - list_len() { - let v = this; - let size = 0; - while (v.listp()) { - size += 1; - v = v.rest(); - } - return size; - } - as_javascript() { - return as_javascript_1.as_javascript(this); - } - toString() { - return this.as_bin().hex(); - } - __repr__() { - return `SExp(${this.as_bin().hex()})`; - } -} -exports.SExp = SExp; -SExp.TRUE = new SExp(new CLVMObject_1.CLVMObject(__type_compatibility__1.Bytes.from("0x01", "hex"))); -SExp.FALSE = new SExp(new CLVMObject_1.CLVMObject(__type_compatibility__1.Bytes.NULL)); -SExp.__NULL__ = new SExp(new CLVMObject_1.CLVMObject(__type_compatibility__1.Bytes.NULL)); -function isSExp(v) { - return v && typeof v.atom !== "undefined" - && typeof v.pair !== "undefined" - && typeof v.first === "function" - && typeof v.rest === "function" - && typeof v.cons === "function"; -} -exports.isSExp = isSExp; diff --git a/.dist/npm/__bls_signatures__.d.ts b/.dist/npm/__bls_signatures__.d.ts deleted file mode 100644 index c5314a6..0000000 --- a/.dist/npm/__bls_signatures__.d.ts +++ /dev/null @@ -1,19 +0,0 @@ -import type { G1Element as G1ElementType, ModuleInstance } from "@chiamine/bls-signatures"; -export declare let BLS: ModuleInstance | undefined; -export declare let loadPromise: Promise | undefined; -/** - * Load BLS Module instance. - * This function must be called an awaited on program start up. - */ -export declare function initializeBLS(): Promise; -/** - * This function must be called after `initializeBLS()` is done. - * Calling `await initializeBLS()` on program startup is library user's responsibility. - * - * This is used for synchronous code execution. - * Within this library, this is always called to get BLS module to keep code synchronous. - */ -export declare function getBLSModule(): ModuleInstance; -export declare function G1Element_from_bytes(bytes: Uint8Array): G1ElementType; -export declare function assert_G1Element_valid(bytes: Uint8Array): void; -export declare function G1Element_add(g1Element1: G1ElementType, g1Element2: G1ElementType): G1ElementType; diff --git a/.dist/npm/__bls_signatures__.js b/.dist/npm/__bls_signatures__.js deleted file mode 100644 index b2ec252..0000000 --- a/.dist/npm/__bls_signatures__.js +++ /dev/null @@ -1,117 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.G1Element_add = exports.assert_G1Element_valid = exports.G1Element_from_bytes = exports.getBLSModule = exports.initializeBLS = exports.loadPromise = exports.BLS = void 0; -const blsLoader = require("@chiamine/bls-signatures"); -/** - * Load BLS Module instance. - * This function must be called an awaited on program start up. - */ -function initializeBLS() { - return __awaiter(this, void 0, void 0, function* () { - if (exports.BLS) { - return exports.BLS; - } - else if (exports.loadPromise) { - return exports.loadPromise; - } - return exports.loadPromise = new Promise((resolve, reject) => { - if (exports.BLS) { - exports.loadPromise = undefined; - return resolve(exports.BLS); - } - blsLoader().then((instance) => { - if (!instance) { - return reject(); - } - exports.loadPromise = undefined; - return resolve(exports.BLS = instance); - }).catch(e => { - console.error("Error while loading BLS module"); - return reject(e); - }); - }); - }); -} -exports.initializeBLS = initializeBLS; -/** - * This function must be called after `initializeBLS()` is done. - * Calling `await initializeBLS()` on program startup is library user's responsibility. - * - * This is used for synchronous code execution. - * Within this library, this is always called to get BLS module to keep code synchronous. - */ -function getBLSModule() { - if (!exports.BLS) { - throw new Error("BLS module has not been loaded. Please call `await initializeBLS()` on start up"); - } - return exports.BLS; -} -exports.getBLSModule = getBLSModule; -function G1Element_from_bytes(bytes) { - assert_G1Element_valid(bytes); - const BLSModule = getBLSModule(); - try { - return BLSModule.G1Element.from_bytes(bytes); - } - catch (e) { - // Print exception message if debug module is enabled and loaded. - const message = "Exception in G1Element operation"; - /* - const get_exception_message = BLS.Util.get_exception_message; - if (typeof get_exception_message === "function") { - message = get_exception_message(e as number); - } - */ - throw new Error(message); - } -} -exports.G1Element_from_bytes = G1Element_from_bytes; -function assert_G1Element_valid(bytes) { - const BLSModule = getBLSModule(); - const { G1Element } = BLSModule; - if (bytes.length !== G1Element.SIZE) { - throw new Error("G1Element: Invalid size"); - } - if ((bytes[0] & 0xc0) === 0xc0) { // representing infinity - if (bytes[0] !== 0xc0) { - throw new Error("G1Element: Given G1 infinity element must be canonical"); - } - for (let i = 1; i < G1Element.SIZE; ++i) { - if (bytes[i] !== 0x00) { - throw new Error("G1Element: Given G1 infinity element must be canonical"); - } - } - } - else { - if ((bytes[0] & 0xc0) !== 0x80) { - throw new Error("Given G1 non-infinity element must start with 0b10"); - } - } -} -exports.assert_G1Element_valid = assert_G1Element_valid; -function G1Element_add(g1Element1, g1Element2) { - try { - return g1Element1.add(g1Element2); - } - catch (e) { - // Print exception message if debug module is enabled and loaded. - const message = "Exception in G1Element operation"; - /* - const get_exception_message = BLS.Util.get_exception_message; - if (typeof get_exception_message === "function") { - message = get_exception_message(e as number); - } - */ - throw new Error(message); - } -} -exports.G1Element_add = G1Element_add; diff --git a/.dist/npm/__debug__.d.ts b/.dist/npm/__debug__.d.ts deleted file mode 100644 index 5d1b270..0000000 --- a/.dist/npm/__debug__.d.ts +++ /dev/null @@ -1 +0,0 @@ -export declare function prettyPrint(enable: boolean): void; diff --git a/.dist/npm/__debug__.js b/.dist/npm/__debug__.js deleted file mode 100644 index 5a5ac59..0000000 --- a/.dist/npm/__debug__.js +++ /dev/null @@ -1,17 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.prettyPrint = void 0; -const SExp_1 = require("./SExp"); -function prettyPrint(enable) { - if (enable) { - const toString = SExp_1.SExp.prototype.toString; - SExp_1.SExp.prototype.toString = SExp_1.SExp.prototype.__repr__; - SExp_1.SExp.prototype.__repr__ = toString; - } - else { - const __repr__ = SExp_1.SExp.prototype.toString; - SExp_1.SExp.prototype.toString = SExp_1.SExp.prototype.__repr__; - SExp_1.SExp.prototype.__repr__ = __repr__; - } -} -exports.prettyPrint = prettyPrint; diff --git a/.dist/npm/__python_types__.d.ts b/.dist/npm/__python_types__.d.ts deleted file mode 100644 index 5a97f7b..0000000 --- a/.dist/npm/__python_types__.d.ts +++ /dev/null @@ -1,19 +0,0 @@ -export declare type int = number; -export declare type int8 = number; -export declare type uint8 = number; -export declare type int16 = number; -export declare type uint16 = number; -export declare type int32 = number; -export declare type uint32 = number; -export declare type int64 = BigInt; -export declare type uint64 = BigInt; -export declare type uint128 = BigInt; -export declare type int512 = BigInt; -export declare type float = number; -export declare type str = string; -export declare type bool = boolean; -export declare type True = true; -export declare type False = false; -export declare const None: null; -export declare type None = null; -export declare type Optional = T | None; diff --git a/.dist/npm/__python_types__.js b/.dist/npm/__python_types__.js deleted file mode 100644 index dfc0d5b..0000000 --- a/.dist/npm/__python_types__.js +++ /dev/null @@ -1,4 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.None = void 0; -exports.None = null; diff --git a/.dist/npm/__type_compatibility__.d.ts b/.dist/npm/__type_compatibility__.d.ts deleted file mode 100644 index 3f5987d..0000000 --- a/.dist/npm/__type_compatibility__.d.ts +++ /dev/null @@ -1,74 +0,0 @@ -import { Word32Array } from "jscrypto/Word32Array"; -import { None, str } from "./__python_types__"; -import { G1Element } from "@chiamine/bls-signatures"; -export declare function to_hexstr(r: Uint8Array): string; -/** - * Get python's bytes.__repr__ style string. - * @see https://github.com/python/cpython/blob/main/Objects/bytesobject.c#L1337 - * @param {Uint8Array} r - byteArray to stringify - */ -export declare function PyBytes_Repr(r: Uint8Array): string; -export declare type BytesFromType = "hex" | "utf8" | "G1Element"; -/** - * Unlike python, there is no immutable byte type in javascript. - */ -export declare class Bytes { - private readonly _b; - static readonly NULL: Bytes; - constructor(value?: Uint8Array | Bytes | None); - static from(value?: Uint8Array | Bytes | number[] | str | G1Element | None, type?: BytesFromType): Bytes; - static SHA256(value: str | Bytes | Uint8Array): Bytes; - get length(): number; - get_byte_at(i: number): number; - concat(b: Bytes): Bytes; - repeat(n: number): Bytes; - slice(start: number, length?: number): Bytes; - as_word(): Word32Array; - data(): Uint8Array; - raw(): Uint8Array; - clone(): Bytes; - toString(): string; - hex(): string; - decode(): string; - startswith(b: Bytes): boolean; - endswith(b: Bytes): boolean; - equal_to(b: Bytes | None | any): boolean; - /** - * Returns: - * +1 if argument is smaller - * 0 if this and argument is the same - * -1 if argument is larger - * @param other - */ - compare(other: Bytes): -1 | 0 | 1; -} -export declare function b(utf8Str: str, type?: "utf8" | "hex"): Bytes; -export declare function h(hexStr: str): Bytes; -export declare function list(iterable: Iterable): T[]; -export declare class Tuple extends Array { - constructor(...items: [T1, T2]); - toString(): string; -} -export declare function t(v1: T1, v2: T2): Tuple; -export declare function isTuple(v: unknown): v is Tuple; -/** - * Check whether an argument is a list and not a tuple - */ -export declare function isList(v: unknown): v is unknown[]; -export declare function isIterable(v: any): v is unknown[]; -export declare function isBytes(v: any): v is Bytes; -export declare class Stream { - static readonly INITIAL_BUFFER_SIZE: number; - private _seek; - private _length; - private _buffer; - private _bufAllocMultiplier; - constructor(b?: Bytes); - get seek(): number; - set seek(value: number); - get length(): number; - protected reAllocate(size?: number): void; - write(b: Bytes): number; - read(size: number): Bytes; - getValue(): Bytes; -} diff --git a/.dist/npm/__type_compatibility__.js b/.dist/npm/__type_compatibility__.js deleted file mode 100644 index be9d43f..0000000 --- a/.dist/npm/__type_compatibility__.js +++ /dev/null @@ -1,377 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.Stream = exports.isBytes = exports.isIterable = exports.isList = exports.isTuple = exports.t = exports.Tuple = exports.list = exports.h = exports.b = exports.Bytes = exports.PyBytes_Repr = exports.to_hexstr = void 0; -const Hex_1 = require("jscrypto/Hex"); -const Utf8_1 = require("jscrypto/Utf8"); -const Word32Array_1 = require("jscrypto/Word32Array"); -const SHA256_1 = require("jscrypto/SHA256"); -const __python_types__1 = require("./__python_types__"); -function to_hexstr(r) { - return (new Word32Array_1.Word32Array(r)).toString(); -} -exports.to_hexstr = to_hexstr; -/** - * Get python's bytes.__repr__ style string. - * @see https://github.com/python/cpython/blob/main/Objects/bytesobject.c#L1337 - * @param {Uint8Array} r - byteArray to stringify - */ -function PyBytes_Repr(r) { - let squotes = 0; - let dquotes = 0; - for (let i = 0; i < r.length; i++) { - const b = r[i]; - const c = String.fromCodePoint(b); - switch (c) { - case "'": - squotes++; - break; - case "\"": - dquotes++; - break; - } - } - let quote = "'"; - if (squotes && !dquotes) { - quote = "\""; - } - let s = "b" + quote; - for (let i = 0; i < r.length; i++) { - const b = r[i]; - const c = String.fromCodePoint(b); - if (c === quote || c === "\\") { - s += "\\" + c; - } - else if (c === "\t") { - s += "\\t"; - } - else if (c === "\n") { - s += "\\n"; - } - else if (c === "\r") { - s += "\\r"; - } - else if (c < " " || b >= 0x7f) { - s += "\\x"; - s += b.toString(16).padStart(2, "0"); - } - else { - s += c; - } - } - s += quote; - return s; -} -exports.PyBytes_Repr = PyBytes_Repr; -/** - * Unlike python, there is no immutable byte type in javascript. - */ -class Bytes { - constructor(value) { - if (value instanceof Uint8Array) { - this._b = value; - } - else if (isBytes(value)) { - this._b = value.raw(); - } - else if (!value || value === __python_types__1.None) { - this._b = new Uint8Array(); - } - else { - throw new Error(`Invalid value: ${JSON.stringify(value)}`); - } - } - static from(value, type) { - if (value === __python_types__1.None || value === undefined) { - return new Bytes(value); - } - else if (value instanceof Uint8Array) { - return new Bytes(value.slice()); - } - else if (isBytes(value)) { - return new Bytes(value.data()); - } - else if (Array.isArray(value) && value.every(v => typeof v === "number")) { - if (value.some(v => (v < 0 || v > 255))) { - throw new Error("Bytes must be in range [0, 256)"); - } - return new Bytes(Uint8Array.from(value)); - } - else if (typeof value === "string") { - if (type === "hex") { - value = value.replace(/^0x/, ""); - return new Bytes(Hex_1.Hex.parse(value).toUint8Array()); - } - else /* if(type === "utf8") */ { - return new Bytes(Utf8_1.Utf8.parse(value).toUint8Array()); - } - } - else if (type === "G1Element") { - if (typeof value.serialize !== "function") { - throw new Error("Invalid G1Element"); - } - const uint8array = value.serialize(); - return new Bytes(uint8array); - } - throw new Error(`Invalid value: ${JSON.stringify(value)}`); - } - static SHA256(value) { - let w; - if (typeof value === "string") { - w = SHA256_1.SHA256.hash(value); - } - else if (value instanceof Uint8Array) { - w = new Word32Array_1.Word32Array(value); - w = SHA256_1.SHA256.hash(w); - } - else if (isBytes(value)) { - w = value.as_word(); - w = SHA256_1.SHA256.hash(w); - } - else { - throw new Error("Invalid argument"); - } - return new Bytes(w.toUint8Array()); - } - get length() { - return this._b.length; - } - get_byte_at(i) { - return this._b[i] | 0; - } - concat(b) { - const thisBin = this._b; - const thatBin = b.raw(); - const concatBin = new Uint8Array(thisBin.length + thatBin.length); - concatBin.set(thisBin, 0); - concatBin.set(thatBin, thisBin.length); - return new Bytes(concatBin); - } - repeat(n) { - const ret = new Uint8Array(this.length * n); - for (let i = 0; i < n; i++) { - ret.set(this._b, i * this.length); - } - return new Bytes(ret); - } - slice(start, length) { - const len = typeof length === "number" ? length : (this.length - start); - return new Bytes(this._b.slice(start, start + len)); - } - as_word() { - return new Word32Array_1.Word32Array(this._b); - } - data() { - return new Uint8Array(this._b); - } - raw() { - return this._b; - } - clone() { - return new Bytes(this._b.slice()); - } - toString() { - return PyBytes_Repr(this._b); - } - hex() { - return to_hexstr(this._b); - } - decode() { - return Utf8_1.Utf8.stringify(this.as_word()); - } - startswith(b) { - return this.hex().startsWith(b.hex()); - } - endswith(b) { - return this.hex().endsWith(b.hex()); - } - equal_to(b) { - if (b === __python_types__1.None) { - return false; - } - else if (typeof b.length === "number" && isBytes(b)) { - return this.compare(b) === 0; - } - else if (typeof b.equal_to === "function") { - return b.equal_to(this); - } - return false; - } - /** - * Returns: - * +1 if argument is smaller - * 0 if this and argument is the same - * -1 if argument is larger - * @param other - */ - compare(other) { - if (this.length !== other.length) { - return this.length > other.length ? 1 : -1; - } - const dv_self = new DataView(this.raw().buffer); - const dv_other = new DataView(other.raw().buffer); - const ui32MaxCount = (this.length / 4) | 0; - for (let i = 0; i < ui32MaxCount; i++) { - const ui32_self = dv_self.getUint32(i * 4); - const ui32_other = dv_other.getUint32(i * 4); - if (ui32_self !== ui32_other) { - return ui32_self > ui32_other ? 1 : -1; - } - } - const offset = ui32MaxCount * 4; - for (let i = offset; i < this.length; i++) { - const ui8_self = dv_self.getUint8(i); - const ui8_other = dv_other.getUint8(i); - if (ui8_self !== ui8_other) { - return ui8_self > ui8_other ? 1 : -1; - } - } - return 0; - } -} -exports.Bytes = Bytes; -Bytes.NULL = new Bytes(); -function b(utf8Str, type = "utf8") { - return Bytes.from(utf8Str, type); -} -exports.b = b; -function h(hexStr) { - return Bytes.from(hexStr, "hex"); -} -exports.h = h; -function list(iterable) { - const arr = []; - for (const item of iterable) { - arr.push(item); - } - return arr; -} -exports.list = list; -class Tuple extends Array { - constructor(...items) { - super(...items); - Object.freeze(this); - return this; - } - toString() { - return `(${this[0]}, ${this[1]})`; - } -} -exports.Tuple = Tuple; -function t(v1, v2) { - return new Tuple(v1, v2); -} -exports.t = t; -function isTuple(v) { - return v instanceof Array && Object.isFrozen(v) && v.length === 2; -} -exports.isTuple = isTuple; -/** - * Check whether an argument is a list and not a tuple - */ -function isList(v) { - return Array.isArray(v) && !isTuple(v); -} -exports.isList = isList; -function isIterable(v) { - if (Array.isArray(v)) { // Including Tuple. - return true; - } - else if (typeof v === "string") { - return false; - } - else if (typeof v[Symbol.iterator] === "function") { - return true; - } - return false; -} -exports.isIterable = isIterable; -function isBytes(v) { - return v && typeof v.length === "number" - && typeof v.get_byte_at === "function" - && typeof v.raw === "function" - && typeof v.data === "function" - && typeof v.hex === "function" - && typeof v.decode === "function" - && typeof v.equal_to === "function" - && typeof v.compare === "function"; -} -exports.isBytes = isBytes; -class Stream { - constructor(b) { - this._bufAllocMultiplier = 4; - this._seek = 0; - if (b) { - if (b.length > Stream.INITIAL_BUFFER_SIZE) { - this._buffer = new Uint8Array(b.length * 2); - } - else { - this._buffer = new Uint8Array(Stream.INITIAL_BUFFER_SIZE); - } - this._buffer.set(b.raw()); - this._length = b.length; - } - else { - this._buffer = new Uint8Array(Stream.INITIAL_BUFFER_SIZE); - this._length = 0; - } - } - get seek() { - return this._seek; - } - set seek(value) { - if (value < 0) { - this._seek = this.length - 1; - } - else if (value > this.length - 1) { - this._seek = this.length; - } - else { - this._seek = value; - } - } - get length() { - return this._length; - } - reAllocate(size) { - let s = typeof size === "number" ? size : this._buffer.length * this._bufAllocMultiplier; - /** - * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Invalid_array_length - */ - if (s > 4294967295) { // 4294967295 = 2**32 - 1 - s = 4294967295; - } - const buf = new Uint8Array(s); - buf.set(this._buffer); - this._buffer = buf; - } - write(b) { - const newLength = Math.max(this.length, b.length + this._seek); - if (newLength > this._buffer.length) { - this.reAllocate(newLength * this._bufAllocMultiplier); - } - const offset = this.seek; - this._buffer.set(b.raw(), offset); - this._length = newLength; - this.seek += b.length; // Don't move this line prior to `this._length = newLength`! - return b.length; - } - read(size) { - if (this.seek > this.length - 1) { - return new Bytes(); // Return empty byte - } - if (this.seek + size <= this.length) { - const u8 = this._buffer.slice(this.seek, this.seek + size); - this.seek += size; - return new Bytes(u8); - } - const u8 = new Uint8Array(this.length - this.seek); - u8.set(this._buffer.subarray(this.seek, this.length)); - this.seek += size; - return new Bytes(u8); - } - getValue() { - return new Bytes(this._buffer.subarray(0, this.length)); - } -} -exports.Stream = Stream; -Stream.INITIAL_BUFFER_SIZE = 64 * 1024; diff --git a/.dist/npm/as_javascript.d.ts b/.dist/npm/as_javascript.d.ts deleted file mode 100644 index 20783e4..0000000 --- a/.dist/npm/as_javascript.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { CastableType, SExp } from "./SExp"; -import { Bytes, Tuple } from "./__type_compatibility__"; -export declare type TOpStack = Array<(op_stack: TOpStack, val_stack: TValStack) => unknown>; -export declare type TValStack = Array>; -export declare type TToSexpF = (arg: CastableType) => SExp; -export declare type TToJavascript = Bytes | Bytes[] | Tuple | TToJavascript[]; -export declare function as_javascript(sexp: SExp): TToJavascript; diff --git a/.dist/npm/as_javascript.js b/.dist/npm/as_javascript.js deleted file mode 100644 index 9836500..0000000 --- a/.dist/npm/as_javascript.js +++ /dev/null @@ -1,59 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.as_javascript = void 0; -const __type_compatibility__1 = require("./__type_compatibility__"); -function as_javascript(sexp) { - function _roll(op_stack, val_stack) { - const v1 = val_stack.pop(); - const v2 = val_stack.pop(); - val_stack.push(v1); - val_stack.push(v2); - } - function _make_tuple(op_stack, val_stack) { - const left = val_stack.pop(); - const right = val_stack.pop(); - if (right.equal_to(__type_compatibility__1.Bytes.NULL)) { - val_stack.push([left]); - } - else { - val_stack.push(__type_compatibility__1.t(left, right)); - } - } - function _extend_list(op_stack, val_stack) { - let left = [val_stack.pop()]; - const right = val_stack.pop(); - left = left.concat(right); - val_stack.push(left); - } - function _as_javascript(op_stack, val_stack) { - const v = val_stack.pop(); - const pair = v.as_pair(); - if (pair) { - const [left, right] = pair; - if (right.listp()) { - op_stack.push(_extend_list); - } - else { - op_stack.push(_make_tuple); - } - op_stack.push(_as_javascript); - op_stack.push(_roll); - op_stack.push(_as_javascript); - val_stack.push(left); - val_stack.push(right); - } - else { - val_stack.push(v.atom); - } - } - const op_stack = [_as_javascript]; - const val_stack = [sexp]; - while (op_stack.length) { - const op_f = op_stack.pop(); - if (op_f) { - op_f(op_stack, val_stack); - } - } - return val_stack[val_stack.length - 1]; -} -exports.as_javascript = as_javascript; diff --git a/.dist/npm/browser/blsjs.wasm b/.dist/npm/browser/blsjs.wasm deleted file mode 100644 index b8f924c..0000000 Binary files a/.dist/npm/browser/blsjs.wasm and /dev/null differ diff --git a/.dist/npm/browser/index.js b/.dist/npm/browser/index.js deleted file mode 100644 index 832b12c..0000000 --- a/.dist/npm/browser/index.js +++ /dev/null @@ -1 +0,0 @@ -!function(n,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.clvm=t():n.clvm=t()}(this,(function(){return n={513:function(n,t,r){var e,i=(e=(e="undefined"!=typeof document&&document.currentScript?document.currentScript.src:void 0)||"/index.js",function(n){var t,i,o;n=n||{},t||(t=void 0!==n?n:{}),t.ready=new Promise((function(n,t){i=n,o=t}));var u,f={};for(u in t)t.hasOwnProperty(u)&&(f[u]=t[u]);var a,c,s,h,l,w="./this.program",v="object"==typeof window,d="function"==typeof importScripts,y="object"==typeof process&&"object"==typeof process.versions&&"string"==typeof process.versions.node,p="";y?(p=d?r(794).dirname(p)+"/":"//",a=function(n,t){return h||(h=r(33)),l||(l=r(794)),n=l.normalize(n),h.readFileSync(n,t?null:"utf8")},s=function(n){return(n=a(n,!0)).buffer||(n=new Uint8Array(n)),n.buffer||Z("Assertion failed: undefined"),n},c=function(n,t,e){h||(h=r(33)),l||(l=r(794)),n=l.normalize(n),h.readFile(n,(function(n,r){n?e(n):t(r.buffer)}))},1=e);)++r;if(16(i=224==(240&i)?(15&i)<<12|o<<6|u:(7&i)<<18|o<<12|u<<6|63&n[t++])?e+=String.fromCharCode(i):(i-=65536,e+=String.fromCharCode(55296|i>>10,56320|1023&i))}}else e+=String.fromCharCode(i)}return e}function O(n,t,r,e){if(!(0=u&&(u=65536+((1023&u)<<10)|1023&n.charCodeAt(++o)),127>=u){if(r>=e)break;t[r++]=u}else{if(2047>=u){if(r+1>=e)break;t[r++]=192|u>>6}else{if(65535>=u){if(r+2>=e)break;t[r++]=224|u>>12}else{if(r+3>=e)break;t[r++]=240|u>>18,t[r++]=128|u>>12&63}t[r++]=128|u>>6&63}t[r++]=128|63&u}}return t[r]=0,r-i}function k(n){for(var t=0,r=0;r=e&&(e=65536+((1023&e)<<10)|1023&n.charCodeAt(++r)),127>=e?++t:t=2047>=e?t+2:65535>=e?t+3:t+4}return t}var U="undefined"!=typeof TextDecoder?new TextDecoder("utf-16le"):void 0;function M(n,t){for(var r=n>>1,e=r+t/2;!(r>=e)&&W[r];)++r;if(32<(r<<=1)-n&&U)return U.decode(P.subarray(n,r));for(r="",e=0;!(e>=t/2);++e){var i=N[n+2*e>>1];if(0==i)break;r+=String.fromCharCode(i)}return r}function T(n,t,r){if(void 0===r&&(r=2147483647),2>r)return 0;var e=t;r=(r-=2)<2*n.length?r/2:n.length;for(var i=0;i>1]=n.charCodeAt(i),t+=2;return N[t>>1]=0,t-e}function S(n){return 2*n.length}function I(n,t){for(var r=0,e="";!(r>=t/4);){var i=$[n+4*r>>2];if(0==i)break;++r,65536<=i?(i-=65536,e+=String.fromCharCode(55296|i>>10,56320|1023&i)):e+=String.fromCharCode(i)}return e}function x(n,t,r){if(void 0===r&&(r=2147483647),4>r)return 0;var e=t;r=e+r-4;for(var i=0;i=o&&(o=65536+((1023&o)<<10)|1023&n.charCodeAt(++i)),$[t>>2]=o,(t+=4)+4>r)break}return $[t>>2]=0,t-e}function F(n){for(var t=0,r=0;r=e&&++r,t+=4}return t}var C,D,P,N,W,$,B,G,q,H,R=[],z=[],V=[];function J(){var n=t.preRun.shift();R.unshift(n)}var X,Y=0,L=null,Q=null;function Z(n){throw t.onAbort&&t.onAbort(n),g(n),E=!0,n=new WebAssembly.RuntimeError("abort("+n+"). Build with -s ASSERTIONS=1 for more info."),o(n),n}function K(){return X.startsWith("data:application/octet-stream;base64,")}if(t.preloadedImages={},t.preloadedAudios={},X="blsjs.wasm",!K()){var nn=X;X=t.locateFile?t.locateFile(nn,p):p+nn}function tn(){var n=X;try{if(n==X&&b)return new Uint8Array(b);if(s)return s(n);throw"both async and sync fetching of the wasm failed"}catch(n){Z(n)}}function rn(n){for(;0>2]=n},this.ob=function(n){$[this.Y+8>>2]=n},this.pb=function(){$[this.Y>>2]=0},this.nb=function(){D[this.Y+12>>0]=0},this.qb=function(){D[this.Y+13>>0]=0},this.cb=function(n,t){this.rb(n),this.ob(t),this.pb(),this.nb(),this.qb()}}function on(n,t){for(var r=0,e=n.length-1;0<=e;e--){var i=n[e];"."===i?n.splice(e,1):".."===i?(n.splice(e,1),r++):r&&(n.splice(e,1),r--)}if(t)for(;r;r--)n.unshift("..");return n}function un(n){var t="/"===n.charAt(0),r="/"===n.substr(-1);return(n=on(n.split("/").filter((function(n){return!!n})),!t).join("/"))||t||(n="."),n&&r&&(n+="/"),(t?"/":"")+n}function fn(n){var t=/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/.exec(n).slice(1);return n=t[0],t=t[1],n||t?(t&&(t=t.substr(0,t.length-1)),n+t):"."}function an(n){if("/"===n)return"/";var t=(n=(n=un(n)).replace(/\/$/,"")).lastIndexOf("/");return-1===t?n:n.substr(t+1)}function cn(){for(var n="",t=!1,r=arguments.length-1;-1<=r&&!t;r--){if("string"!=typeof(t=0<=r?arguments[r]:"/"))throw new TypeError("Arguments to path.resolve must be strings");if(!t)return"";n=t+"/"+n,t="/"===t.charAt(0)}return(t?"/":"")+(n=on(n.split("/").filter((function(n){return!!n})),!t).join("/"))||"."}var sn=[];function hn(n,t){sn[n]={input:[],output:[],sa:t},Nn(n,ln)}var ln={open:function(n){var t=sn[n.node.rdev];if(!t)throw new jn(43);n.tty=t,n.seekable=!1},close:function(n){n.tty.sa.flush(n.tty)},flush:function(n){n.tty.sa.flush(n.tty)},read:function(n,t,r,e){if(!n.tty||!n.tty.sa.Ra)throw new jn(60);for(var i=0,o=0;o=t||(t=Math.max(t,r*(1048576>r?2:1.125)>>>0),0!=r&&(t=Math.max(t,256)),r=n.W,n.W=new Uint8Array(t),0=n.node.aa)return 0;if(8<(n=Math.min(n.node.aa-i,e))&&o.subarray)t.set(o.subarray(i,i+n),r);else for(e=0;et)throw new jn(28);return t},La:function(n,t,r){dn.Oa(n.node,t+r),n.node.aa=Math.max(n.node.aa,t+r)},Sa:function(n,t,r,e,i,o){if(0!==t)throw new jn(28);if(32768!=(61440&n.node.mode))throw new jn(43);if(n=n.node.W,2&o||n.buffer!==C){if((0>>0)%gn.length}function Mn(n,t){var r;if(r=(r=xn(n,"x"))?r:n.X.lookup?0:2)throw new jn(r,n);for(r=gn[Un(n.id,t)];r;r=r.gb){var e=r.name;if(r.parent.id===n.id&&e===t)return r}return n.X.lookup(n,t)}function Tn(n,t,r,e){return t=Un((n=new hr(n,t,r,e)).parent.id,n.name),n.gb=gn[t],gn[t]=n}var Sn={r:0,"r+":2,w:577,"w+":578,a:1089,"a+":1090};function In(n){var t=["r","w","rw"][3&n];return 512&n&&(t+="w"),t}function xn(n,t){return An?0:!t.includes("r")||292&n.mode?t.includes("w")&&!(146&n.mode)||t.includes("x")&&!(73&n.mode)?2:0:2}function Fn(n,t){try{return Mn(n,t),20}catch(n){}return xn(n,"wx")}function Cn(n){Xn||((Xn=function(){}).prototype={});var t,r=new Xn;for(t in n)r[t]=n[t];return n=r,r=function(){for(var n=0;n<=4096;n++)if(!bn[n])return n;throw new jn(33)}(),n.fd=r,bn[r]=n}var Dn,Pn={open:function(n){n.$=pn[n.node.rdev].$,n.$.open&&n.$.open(n)},va:function(){throw new jn(70)}};function Nn(n,t){pn[n]={$:t}}function Wn(n,t){var r="/"===t,e=!t;if(r&&yn)throw new jn(10);if(!r&&!e){var i=On(t,{Qa:!1});if(t=i.path,(i=i.node).Ca)throw new jn(10);if(16384!=(61440&i.mode))throw new jn(54)}t={type:n,Ab:{},Ta:t,fb:[]},(n=n.la(t)).la=t,t.root=n,r?yn=n:i&&(i.Ca=t,i.la&&i.la.fb.push(t))}function $n(n,t,r){var e=On(n,{parent:!0}).node;if(!(n=an(n))||"."===n||".."===n)throw new jn(28);var i=Fn(e,n);if(i)throw new jn(i);if(!e.X.Ba)throw new jn(63);return e.X.Ba(e,n,t,r)}function Bn(n){return $n(n,16895,0)}function Gn(n,t,r){void 0===r&&(r=t,t=438),$n(n,8192|t,r)}function qn(n,t){if(!cn(n))throw new jn(44);var r=On(t,{parent:!0}).node;if(!r)throw new jn(44);var e=Fn(r,t=an(t));if(e)throw new jn(e);if(!r.X.symlink)throw new jn(63);r.X.symlink(r,t,n)}function Hn(n){if(!(n=On(n).node))throw new jn(44);if(!n.X.readlink)throw new jn(28);return cn(kn(n.parent),n.X.readlink(n))}function Rn(n,r,e){if(""===n)throw new jn(44);if("string"==typeof r){var i=Sn[r];if(void 0===i)throw Error("Unknown file open mode: "+r);r=i}if(e=64&r?4095&(void 0===e?438:e)|32768:0,"object"==typeof n)var o=n;else{n=un(n);try{o=On(n,{Pa:!(131072&r)}).node}catch(n){}}if(i=!1,64&r)if(o){if(128&r)throw new jn(20)}else o=$n(n,e,0),i=!0;if(!o)throw new jn(44);if(8192==(61440&o.mode)&&(r&=-513),65536&r&&16384!=(61440&o.mode))throw new jn(54);if(!i&&(e=o?40960==(61440&o.mode)?32:16384==(61440&o.mode)&&("r"!==In(r)||512&r)?31:xn(o,In(r)):44))throw new jn(e);if(512&r){if(!(e="string"==typeof(e=o)?On(e,{Pa:!0}).node:e).X.ja)throw new jn(63);if(16384==(61440&e.mode))throw new jn(31);if(32768!=(61440&e.mode))throw new jn(28);if(i=xn(e,"w"))throw new jn(i);e.X.ja(e,{size:0,timestamp:Date.now()})}r&=-131713,(o=Cn({node:o,path:kn(o),flags:r,seekable:!0,position:0,$:o.$,Cb:[],error:!1})).$.open&&o.$.open(o),!t.logReadFiles||1&r||(Yn||(Yn={}),n in Yn||(Yn[n]=1,g("FS.trackingDelegate error on read file: "+n)));try{En.onOpenFile&&(e=0,1!=(2097155&r)&&(e|=1),0!=(2097155&r)&&(e|=2),En.onOpenFile(n,e))}catch(t){g("FS.trackingDelegate['onOpenFile']('"+n+"', flags) threw an exception: "+t.message)}return o}function zn(){jn||((jn=function(n,t){this.node=t,this.mb=function(n){this.ua=n},this.mb(n),this.message="FS error"}).prototype=Error(),jn.prototype.constructor=jn,[44].forEach((function(n){_n[n]=new jn(n),_n[n].stack=""})))}function Vn(n,t,r){n=un("/dev/"+n);var e=function(n,t){var r=0;return n&&(r|=365),t&&(r|=146),r}(!!t,!!r);Jn||(Jn=64);var i=Jn++<<8|0;Nn(i,{open:function(n){n.seekable=!1},close:function(){r&&r.buffer&&r.buffer.length&&r(10)},read:function(n,r,e,i){for(var o=0,u=0;u=t?"_"+n:n}function ut(n,t){return n=ot(n),new Function("body","return function "+n+'() {\n "use strict"; return body.apply(this, arguments);\n};\n')(t)}function ft(n){var t=Error,r=ut(n,(function(t){this.name=n,this.message=t,void 0!==(t=Error(t).stack)&&(this.stack=this.toString()+"\n"+t.replace(/^Error(:[^\n]*)?\n/,""))}));return r.prototype=Object.create(t.prototype),r.prototype.constructor=r,r.prototype.toString=function(){return void 0===this.message?this.name:this.name+": "+this.message},r}var at=void 0;function ct(n){throw new at(n)}var st=void 0;function ht(n){throw new st(n)}function lt(n,t,r){function e(t){(t=r(t)).length!==n.length&&ht("Mismatched type converter count");for(var e=0;e>2])}function It(n,t,r){return t===r?n:void 0===r.ha||null===(n=It(n,t,r.ha))?null:r.Ya(n)}var xt={};function Ft(n,t){return t.ba&&t.Y||ht("makeClassHandle requires ptr and ptrType"),!!t.ga!=!!t.fa&&ht("Both smartPtrType and smartPtr must be specified"),t.count={value:1},bt(Object.create(n,{V:{value:t}}))}function Ct(n,t,r,e){this.name=n,this.Z=t,this.Ha=r,this.za=e,this.Aa=!1,this.oa=this.kb=this.jb=this.Va=this.sb=this.hb=void 0,void 0!==t.ha?this.toWireType=Mt:(this.toWireType=e?Ut:Tt,this.ka=null)}function Dt(n,r){var e=(n=tt(n)).includes("j")?function(n,r){var e=[];return function(){e.length=arguments.length;for(var i=0;io&&ct("argTypes array size mismatch! Must at least get return value and 'this' types!");var u=null!==t[1]&&null!==r,f=!1;for(r=1;r>2)+e]);return r}var Ht=[],Rt=[{},{value:void 0},{value:null},{value:!0},{value:!1}];function zt(n){4>2])};case 3:return function(n){return this.fromWireType(q[n>>3])};default:throw new TypeError("Unknown float type: "+n)}}function Yt(n,t,r){switch(t){case 0:return r?function(n){return D[n]}:function(n){return P[n]};case 1:return r?function(n){return N[n>>1]}:function(n){return W[n>>1]};case 2:return r?function(n){return $[n>>2]}:function(n){return B[n>>2]};default:throw new TypeError("Unknown integer type: "+n)}}function Lt(n){return n||ct("Cannot use deleted val. handle = "+n),Rt[n].value}function Qt(n,t){var r=et[n];return void 0===r&&ct(t+" has unknown type "+Nt(n)),r}var Zt={};function Kt(n){var t=Zt[n];return void 0===t?tt(n):t}var nr=[];function tr(){return"object"==typeof globalThis?globalThis:Function("return this")()}var rr,er={},ir={};function or(){if(!rr){var n,t={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:("object"==typeof navigator&&navigator.languages&&navigator.languages[0]||"C").replace("-","_")+".UTF-8",_:w||"./this.program"};for(n in ir)void 0===ir[n]?delete t[n]:t[n]=ir[n];var r=[];for(n in t)r.push(n+"="+t[n]);rr=r}return rr}function ur(n){return 0==n%4&&(0!=n%100||0==n%400)}function fr(n,t){for(var r=0,e=0;e<=t;r+=n[e++]);return r}var ar=[31,29,31,30,31,30,31,31,30,31,30,31],cr=[31,28,31,30,31,30,31,31,30,31,30,31];function sr(n,t){for(n=new Date(n.getTime());0e-n.getDate())){n.setDate(n.getDate()+t);break}t-=e-n.getDate()+1,n.setDate(1),11>r?n.setMonth(r+1):(n.setMonth(0),n.setFullYear(n.getFullYear()+1))}return n}function hr(n,t,r,e){n||(n=this),this.parent=n,this.la=n.la,this.Ca=null,this.id=mn++,this.name=t,this.mode=r,this.X={},this.$={},this.rdev=e}Object.defineProperties(hr.prototype,{read:{get:function(){return 365==(365&this.mode)},set:function(n){n?this.mode|=365:this.mode&=-366}},write:{get:function(){return 146==(146&this.mode)},set:function(n){n?this.mode|=146:this.mode&=-147}}}),zn(),gn=Array(4096),Wn(dn,"/"),Bn("/tmp"),Bn("/home"),Bn("/home/web_user"),function(){Bn("/dev"),Nn(259,{read:function(){return 0},write:function(n,t,r,e){return e}}),Gn("/dev/null",259),hn(1280,wn),hn(1536,vn),Gn("/dev/tty",1280),Gn("/dev/tty1",1536);var n=function(){if("object"==typeof crypto&&"function"==typeof crypto.getRandomValues){var n=new Uint8Array(1);return function(){return crypto.getRandomValues(n),n[0]}}if(y)try{var t=r(135);return function(){return t.randomBytes(1)[0]}}catch(n){}return function(){Z("randomDevice")}}();Vn("random",n),Vn("urandom",n),Bn("/dev/shm"),Bn("/dev/shm/tmp")}(),function(){Bn("/proc");var n=Bn("/proc/self");Bn("/proc/self/fd"),Wn({la:function(){var t=Tn(n,"fd",16895,73);return t.X={lookup:function(n,t){var r=bn[+t];if(!r)throw new jn(8);return(n={parent:null,la:{Ta:"fake"},X:{readlink:function(){return r.path}}}).parent=n}},t}},"/proc/self/fd")}();for(var lr=Array(256),wr=0;256>wr;++wr)lr[wr]=String.fromCharCode(wr);function vr(n,t){var r=Array(k(n)+1);return n=O(n,r,0,r.length),t&&(r.length=n),r}nt=lr,at=t.BindingError=ft("BindingError"),st=t.InternalError=ft("InternalError"),Et.prototype.isAliasOf=function(n){if(!(this instanceof Et&&n instanceof Et))return!1;var t=this.V.ba.Z,r=this.V.Y,e=n.V.ba.Z;for(n=n.V.Y;t.ha;)r=t.ya(r),t=t.ha;for(;e.ha;)n=e.ya(n),e=e.ha;return t===e&&r===n},Et.prototype.clone=function(){if(this.V.Y||vt(this),this.V.wa)return this.V.count.value+=1,this;var n=bt,t=Object,r=t.create,e=Object.getPrototypeOf(this),i=this.V;return(n=n(r.call(t,e,{V:{value:{count:i.count,qa:i.qa,wa:i.wa,Y:i.Y,ba:i.ba,fa:i.fa,ga:i.ga}}}))).V.count.value+=1,n.V.qa=!1,n},Et.prototype.delete=function(){this.V.Y||vt(this),this.V.qa&&!this.V.wa&&ct("Object already scheduled for deletion"),yt(this),pt(this.V),this.V.wa||(this.V.fa=void 0,this.V.Y=void 0)},Et.prototype.isDeleted=function(){return!this.V.Y},Et.prototype.deleteLater=function(){return this.V.Y||vt(this),this.V.qa&&!this.V.wa&&ct("Object already scheduled for deletion"),gt.push(this),1===gt.length&&mt&&mt(At),this.V.qa=!0,this},Ct.prototype.$a=function(n){return this.Va&&(n=this.Va(n)),n},Ct.prototype.Na=function(n){this.oa&&this.oa(n)},Ct.prototype.argPackAdvance=8,Ct.prototype.readValueFromPointer=St,Ct.prototype.deleteObject=function(n){null!==n&&n.delete()},Ct.prototype.fromWireType=function(n){function t(){return this.Aa?Ft(this.Z.ra,{ba:this.hb,Y:r,ga:this,fa:n}):Ft(this.Z.ra,{ba:this,Y:n})}var r=this.$a(n);if(!r)return this.Na(n),null;var e=function(n,t){for(void 0===t&&ct("ptr should not be undefined");n.ha;)t=n.ya(t),n=n.ha;return xt[t]}(this.Z,r);if(void 0!==e)return 0===e.V.count.value?(e.V.Y=r,e.V.fa=n,e.clone()):(e=e.clone(),this.Na(n),e);if(e=this.Z.Za(r),!(e=jt[e]))return t.call(this);e=this.za?e.Xa:e.pointerType;var i=It(r,this.Z,e.Z);return null===i?t.call(this):this.Aa?Ft(e.Z.ra,{ba:e,Y:i,ga:this,fa:n}):Ft(e.Z.ra,{ba:e,Y:i})},t.getInheritedInstanceCount=function(){return Object.keys(xt).length},t.getLiveInheritedInstances=function(){var n,t=[];for(n in xt)xt.hasOwnProperty(n)&&t.push(xt[n]);return t},t.flushPendingDeletes=At,t.setDelayFunction=function(n){mt=n,gt.length&&mt&&mt(At)},Pt=t.UnboundTypeError=ft("UnboundTypeError"),t.count_emval_handles=function(){for(var n=0,t=5;t>2];else i=0;return Rn(e,t,i).fd}catch(n){return void 0!==Ln&&n instanceof jn||Z(n),-n.ua}},w:function(){},F:function(n,t,r,e,i){var o=Kn(r);wt(n,{name:t=tt(t),fromWireType:function(n){return!!n},toWireType:function(n,t){return t?e:i},argPackAdvance:8,readValueFromPointer:function(n){if(1===r)var e=D;else if(2===r)e=N;else{if(4!==r)throw new TypeError("Unknown boolean type size: "+t);e=$}return this.fromWireType(e[n>>o])},ka:null})},l:function(n,r,e,i,o,u,f,a,c,s,h,l,w){h=tt(h),u=Dt(o,u),a&&(a=Dt(f,a)),s&&(s=Dt(c,s)),w=Dt(l,w);var v=ot(h);!function(n,r){t.hasOwnProperty(n)?(ct("Cannot register public name '"+n+"' twice"),_t(t,n,n),t.hasOwnProperty(void 0)&&ct("Cannot register multiple overloads of a function with the same number of arguments (undefined)!"),t[n].da[void 0]=r):t[n]=r}(v,(function(){Wt("Cannot construct "+h+" due to unbound types",[i])})),lt([n,r,e],i?[i]:[],(function(r){if(r=r[0],i)var e=r.Z,o=e.ra;else o=Et.prototype;r=ut(v,(function(){if(Object.getPrototypeOf(this)!==f)throw new at("Use 'new' to construct "+h);if(void 0===c.na)throw new at(h+" has no accessible constructor");var n=c.na[arguments.length];if(void 0===n)throw new at("Tried to invoke ctor of "+h+" with invalid number of parameters ("+arguments.length+") - expected ("+Object.keys(c.na).toString()+") parameters instead!");return n.apply(this,arguments)}));var f=Object.create(o,{constructor:{value:r}});r.prototype=f;var c=new Ot(h,r,f,w,e,u,a,s);e=new Ct(h,c,!0,!1),o=new Ct(h+"*",c,!1,!1);var l=new Ct(h+" const*",c,!1,!0);return jt[n]={pointerType:o,Xa:l},function(n,r){t.hasOwnProperty(n)||ht("Replacing nonexistant public symbol"),t[n]=r,t[n].pa=void 0}(v,r),[e,o,l]}))},b:function(n,t,r,e,i,o,u){var f=qt(r,e);t=tt(t),o=Dt(i,o),lt([],[n],(function(n){function e(){Wt("Cannot call "+i+" due to unbound types",f)}var i=(n=n[0]).name+"."+t;t.startsWith("@@")&&(t=Symbol[t.substring(2)]);var a=n.Z.constructor;return void 0===a[t]?(e.pa=r-1,a[t]=e):(_t(a,t,i),a[t].da[r-1]=e),lt([],f,(function(n){return n=[n[0],null].concat(n.slice(1)),n=Gt(i,n,null,o,u),void 0===a[t].da?(n.pa=r-1,a[t]=n):a[t].da[r-1]=n,[]})),[]}))},p:function(n,t,r,e,i,o,u,f){t=tt(t),o=Dt(i,o),lt([],[n],(function(n){var i=(n=n[0]).name+"."+t,a={get:function(){Wt("Cannot access "+i+" due to unbound types",[r])},enumerable:!0,configurable:!0};return a.set=f?function(){Wt("Cannot access "+i+" due to unbound types",[r])}:function(){ct(i+" is a read-only property")},Object.defineProperty(n.Z.constructor,t,a),lt([],[r],(function(r){r=r[0];var i={get:function(){return r.fromWireType(o(e))},enumerable:!0};return f&&(f=Dt(u,f),i.set=function(n){var t=[];f(e,r.toWireType(t,n)),Bt(t)}),Object.defineProperty(n.Z.constructor,t,i),[]})),[]}))},r:function(n,t,r,e,i,o){0>>f}}var a=t.includes("unsigned");wt(n,{name:t,fromWireType:o,toWireType:function(n,r){if("number"!=typeof r&&"boolean"!=typeof r)throw new TypeError('Cannot convert "'+Jt(r)+'" to '+this.name);if(ri)throw new TypeError('Passing a number "'+Jt(r)+'" from JS side to C/C++ side to an argument of type "'+t+'", which is outside the valid range ['+e+", "+i+"]!");return a?r>>>0:0|r},argPackAdvance:8,readValueFromPointer:Yt(t,u,0!==e),ka:null})},g:function(n,t,r){function e(n){var t=B;return new i(C,t[1+(n>>=2)],t[n])}var i=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array][t];wt(n,{name:r=tt(r),fromWireType:e,argPackAdvance:8,readValueFromPointer:e},{bb:!0})},t:function(n,t){var r="std::string"===(t=tt(t));wt(n,{name:t,fromWireType:function(n){var t=B[n>>2];if(r)for(var e=n+4,i=0;i<=t;++i){var o=n+4+i;if(i==t||0==P[o]){if(e=e?_(P,e,o-e):"",void 0===u)var u=e;else u+=String.fromCharCode(0),u+=e;e=o+1}}else{for(u=Array(t),i=0;i>2]=i,r&&e)O(t,P,o+4,i+1);else if(e)for(e=0;e>2],o=u(),a=n+4,c=0;c<=i;++c){var s=n+4+c*t;c!=i&&0!=o[s>>f]||(a=e(a,s-a),void 0===r?r=a:(r+=String.fromCharCode(0),r+=a),a=s+t)}return br(n),r},toWireType:function(n,e){"string"!=typeof e&&ct("Cannot pass non-string to C++ string type "+r);var u=o(e),a=pr(4+u+t);return B[a>>2]=u>>f,i(e,a+4,u+t),null!==n&&n.push(br,a),a},argPackAdvance:8,readValueFromPointer:St,ka:function(n){br(n)}})},G:function(n,t){wt(n,{eb:!0,name:t=tt(t),argPackAdvance:0,fromWireType:function(){},toWireType:function(){}})},i:function(n,t,r){n=Lt(n),t=Qt(t,"emval::as");var e=[],i=Vt(e);return $[r>>2]=i,t.toWireType(e,n)},H:function(n,t,r,e,i){n=nr[n],t=Lt(t),r=Kt(r);var o=[];return $[e>>2]=Vt(o),n(t,r,o,i)},I:function(n,t,r,e){(n=nr[n])(t=Lt(t),r=Kt(r),null,e)},a:zt,v:function(n){return 0===n?Vt(tr()):(n=Kt(n),Vt(tr()[n]))},u:function(n,t){for(var r=(t=function(n,t){for(var r=Array(n),e=0;e>2)+e],"parameter "+e);return r}(n,t))[0],e=r.name+"_$"+t.slice(1).map((function(n){return n.name})).join("_")+"$",i=["retType"],o=[r],u="",f=0;f>> 2) + "+u+'], "parameter '+u+'");\nvar arg'+u+" = argType"+u+".readValueFromPointer(args);\nargs += argType"+u+"['argPackAdvance'];\n";o=new Function("requireRegisteredType","Module","__emval_register",f+"var obj = new constructor("+o+");\nreturn __emval_register(obj);\n}\n")(Qt,t,Vt),er[r]=o}return o(n,e,i)},m:function(n){return Vt(Kt(n))},h:function(n){Bt(Rt[n].value),zt(n)},n:function(n,t){return Vt(n=(n=Qt(n,"_emval_take_value")).readValueFromPointer(t))},q:function(){Z()},x:function(){Z("OOM")},z:function(n,t){try{var r=0;return or().forEach((function(e,i){var o=t+r;for(i=$[n+4*i>>2]=o,o=0;o>0]=e.charCodeAt(o);D[i>>0]=0,r+=e.length+1})),0}catch(n){return void 0!==Ln&&n instanceof jn||Z(n),n.ua}},A:function(n,t){try{var r=or();$[n>>2]=r.length;var e=0;return r.forEach((function(n){e+=n.length+1})),$[t>>2]=e,0}catch(n){return void 0!==Ln&&n instanceof jn||Z(n),n.ua}},B:function(n){try{var t=Zn(n);if(null===t.fd)throw new jn(8);t.ab&&(t.ab=null);try{t.$.close&&t.$.close(t)}catch(n){throw n}finally{bn[t.fd]=null}return t.fd=null,0}catch(n){return void 0!==Ln&&n instanceof jn||Z(n),n.ua}},C:function(n,t,r,e){try{n:{for(var i=Zn(n),o=n=0;o>2],f=i,a=$[t+8*o>>2],c=u,s=void 0,h=D;if(0>c||0>s)throw new jn(28);if(null===f.fd)throw new jn(8);if(1==(2097155&f.flags))throw new jn(8);if(16384==(61440&f.node.mode))throw new jn(31);if(!f.$.read)throw new jn(28);var l=void 0!==s;if(l){if(!f.seekable)throw new jn(70)}else s=f.position;var w=f.$.read(f,h,a,c,s);l||(f.position+=w);var v=w;if(0>v){var d=-1;break n}if(n+=v,v>2]=d,0}catch(n){return void 0!==Ln&&n instanceof jn||Z(n),n.ua}},y:function(n,t,r,e){return function(n,t,r,e){function i(n,t,r){for(n="number"==typeof n?n.toString():n||"";n.lengthn?-1:0=u(r,n)?0>=u(t,n)?n.getFullYear()+1:n.getFullYear():n.getFullYear()-1}var c=$[e+40>>2];for(var s in e={vb:$[e>>2],ub:$[e+4>>2],Da:$[e+8>>2],xa:$[e+12>>2],ta:$[e+16>>2],ea:$[e+20>>2],Ea:$[e+24>>2],Fa:$[e+28>>2],Bb:$[e+32>>2],tb:$[e+36>>2],wb:c&&c?_(P,c,void 0):""},r=r?_(P,r,void 0):"",c={"%c":"%a %b %d %H:%M:%S %Y","%D":"%m/%d/%y","%F":"%Y-%m-%d","%h":"%b","%r":"%I:%M:%S %p","%R":"%H:%M","%T":"%H:%M:%S","%x":"%m/%d/%y","%X":"%H:%M:%S","%Ec":"%c","%EC":"%C","%Ex":"%m/%d/%y","%EX":"%H:%M:%S","%Ey":"%y","%EY":"%Y","%Od":"%d","%Oe":"%e","%OH":"%H","%OI":"%I","%Om":"%m","%OM":"%M","%OS":"%S","%Ou":"%u","%OU":"%U","%OV":"%V","%Ow":"%w","%OW":"%W","%Oy":"%y"})r=r.replace(new RegExp(s,"g"),c[s]);var h="Sunday Monday Tuesday Wednesday Thursday Friday Saturday".split(" "),l="January February March April May June July August September October November December".split(" ");for(s in c={"%a":function(n){return h[n.Ea].substring(0,3)},"%A":function(n){return h[n.Ea]},"%b":function(n){return l[n.ta].substring(0,3)},"%B":function(n){return l[n.ta]},"%C":function(n){return o((n.ea+1900)/100|0,2)},"%d":function(n){return o(n.xa,2)},"%e":function(n){return i(n.xa,2," ")},"%g":function(n){return a(n).toString().substring(2)},"%G":function(n){return a(n)},"%H":function(n){return o(n.Da,2)},"%I":function(n){return 0==(n=n.Da)?n=12:12n.Da?"AM":"PM"},"%S":function(n){return o(n.vb,2)},"%t":function(){return"\t"},"%u":function(n){return n.Ea||7},"%U":function(n){var t=new Date(n.ea+1900,0,1),r=0===t.getDay()?t:sr(t,7-t.getDay());return 0>u(r,n=new Date(n.ea+1900,n.ta,n.xa))?o(Math.ceil((31-r.getDate()+(fr(ur(n.getFullYear())?ar:cr,n.getMonth()-1)-31)+n.getDate())/7),2):0===u(r,t)?"01":"00"},"%V":function(n){var t=new Date(n.ea+1901,0,4),r=f(new Date(n.ea+1900,0,4));t=f(t);var e=sr(new Date(n.ea+1900,0,1),n.Fa);return 0>u(e,r)?"53":0>=u(t,e)?"01":o(Math.ceil((r.getFullYear()u(r,n=new Date(n.ea+1900,n.ta,n.xa))?o(Math.ceil((31-r.getDate()+(fr(ur(n.getFullYear())?ar:cr,n.getMonth()-1)-31)+n.getDate())/7),2):0===u(r,t)?"01":"00"},"%y":function(n){return(n.ea+1900).toString().substring(2)},"%Y":function(n){return n.ea+1900},"%z":function(n){var t=0<=(n=n.tb);return n=Math.abs(n)/60,(t?"+":"-")+String("0000"+(n/60*100+n%60)).slice(-4)},"%Z":function(n){return n.wb},"%%":function(){return"%"}})r.includes(s)&&(r=r.replace(new RegExp(s,"g"),c[s](e)));return(s=vr(r,!1)).length>t?0:(D.set(s,n),s.length-1)}(n,t,r,e)}};!function(){function n(n){t.asm=n.exports,A=t.asm.K,C=n=A.buffer,t.HEAP8=D=new Int8Array(n),t.HEAP16=N=new Int16Array(n),t.HEAP32=$=new Int32Array(n),t.HEAPU8=P=new Uint8Array(n),t.HEAPU16=W=new Uint16Array(n),t.HEAPU32=B=new Uint32Array(n),t.HEAPF32=G=new Float32Array(n),t.HEAPF64=q=new Float64Array(n),H=t.asm.N,z.unshift(t.asm.L),Y--,t.monitorRunDependencies&&t.monitorRunDependencies(Y),0==Y&&(null!==L&&(clearInterval(L),L=null),Q&&(n=Q,Q=null,n()))}function r(t){n(t.instance)}function e(n){return function(){if(!b&&(v||d)){if("function"==typeof fetch&&!X.startsWith("file://"))return fetch(X,{credentials:"same-origin"}).then((function(n){if(!n.ok)throw"failed to load wasm binary file at '"+X+"'";return n.arrayBuffer()})).catch((function(){return tn()}));if(c)return new Promise((function(n,t){c(X,(function(t){n(new Uint8Array(t))}),t)}))}return Promise.resolve().then((function(){return tn()}))}().then((function(n){return WebAssembly.instantiate(n,i)})).then(n,(function(n){g("failed to asynchronously prepare wasm: "+n),Z(n)}))}var i={a:dr};if(Y++,t.monitorRunDependencies&&t.monitorRunDependencies(Y),t.instantiateWasm)try{return t.instantiateWasm(i,n)}catch(n){return g("Module.instantiateWasm callback failed with error: "+n),!1}(b||"function"!=typeof WebAssembly.instantiateStreaming||K()||X.startsWith("file://")||"function"!=typeof fetch?e(r):fetch(X,{credentials:"same-origin"}).then((function(n){return WebAssembly.instantiateStreaming(n,i).then(r,(function(n){return g("wasm streaming compile failed: "+n),g("falling back to ArrayBuffer instantiation"),e(r)}))}))).catch(o)}(),t.nn=function(){return(t.nn=t.asm.L).apply(null,arguments)};var yr,pr=t.tn=function(){return(pr=t.tn=t.asm.M).apply(null,arguments)},br=t.rn=function(){return(br=t.rn=t.asm.O).apply(null,arguments)},mr=t.en=function(){return(mr=t.en=t.asm.P).apply(null,arguments)};function gr(){function n(){if(!yr&&(yr=!0,t.calledRun=!0,!E)){if(t.noFSInit||Dn||(Dn=!0,zn(),t.stdin=t.stdin,t.stdout=t.stdout,t.stderr=t.stderr,t.stdin?Vn("stdin",t.stdin):qn("/dev/tty","/dev/stdin"),t.stdout?Vn("stdout",null,t.stdout):qn("/dev/tty","/dev/stdout"),t.stderr?Vn("stderr",null,t.stderr):qn("/dev/tty1","/dev/stderr"),Rn("/dev/stdin",0),Rn("/dev/stdout",1),Rn("/dev/stderr",1)),An=!1,rn(z),i(t),t.onRuntimeInitialized&&t.onRuntimeInitialized(),t.postRun)for("function"==typeof t.postRun&&(t.postRun=[t.postRun]);t.postRun.length;){var n=t.postRun.shift();V.unshift(n)}rn(V)}}if(!(0"===n?o>t:">="===n?o>=t:o===t))}("<",11))return console.warn("IE <= 10 uses insecure random generator. Please consider to use IE11 or another modern browser"),function(){return Math.floor(512*Math.random())%256};throw new Error("Crypto module not found")}return function(){return t.getRandomValues(new Uint32Array(1))[0]}}return void 0!==n.g&&n.g.crypto?function(){return n.g.crypto.randomBytes(4).readInt32LE()}:function(){return r(845).randomBytes(4).readInt32LE()}}(),f=function(){function n(t,r){if(Array.isArray(t)||!t)return this.i=Array.isArray(t)?t:[],void(this.u="number"==typeof r?r:4*this.i.length);if(t instanceof n)return this.i=t.words.slice(),void(this.u=t.nSigBytes);var e;try{t instanceof ArrayBuffer?e=new Uint8Array(t):(t instanceof Uint8Array||t instanceof Int8Array||t instanceof Uint8ClampedArray||t instanceof Int16Array||t instanceof Uint16Array||t instanceof Int32Array||t instanceof Uint32Array||t instanceof Float32Array||t instanceof Float64Array)&&(e=new Uint8Array(t.buffer,t.byteOffset,t.byteLength))}catch(n){throw new Error("Invalid argument")}if(!e)throw new Error("Invalid argument");for(var i=e.byteLength,o=[],u=0;u>>2]|=e[u]<<24-u%4*8;this.i=o,this.u=i}return Object.defineProperty(n.prototype,"nSigBytes",{get:function(){return this.u},set:function(n){this.u=n},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"words",{get:function(){return this.i},enumerable:!1,configurable:!0}),n.prototype.toString=function(n){return n?n.stringify(this):a.stringify(this)},n.prototype.toUint8Array=function(){for(var n=this.i,t=this.u,r=new Uint8Array(t),e=0;e>>2]>>>24-e%4*8&255;return r},n.prototype.concat=function(n){var t=n.words.slice(),r=n.nSigBytes;if(this.clamp(),this.u%4)for(var e=0;e>>2]>>>24-e%4*8&255;this.i[this.u+e>>>2]|=i<<24-(this.u+e)%4*8}else for(e=0;e>>2]=t[e>>>2];return this.u+=r,this},n.prototype.clamp=function(){var n=this.u;this.i[n>>>2]&=4294967295<<32-n%4*8,this.i.length=Math.ceil(n/4)},n.prototype.clone=function(){return new n(this.i.slice(),this.u)},n.random=function(t){for(var r=[],e=0;e>>2]>>>24-i%4*8&255;e.push((o>>>4).toString(16)),e.push((15&o).toString(16))}return e.join("")},parse:function(n){var t=n.length;if(t%2!=0)throw new Error("Hex string count must be even");if(!/^[a-fA-F0-9]+$/.test(n))throw new Error("Invalid Hex string: "+n);for(var r=[],e=0;e>>3]|=parseInt(n.substr(e,2),16)<<24-e%8*4;return new f(r,t/2)}};return t}()},915:function(n,t,r){n.exports=function(){"use strict";var n={3354:function(n,t,r){r.d(t,{e:function(){return o}});var e=r(5720),i=r(9054),o=function(){function n(t,r){if(Array.isArray(t)||!t)return this.t=Array.isArray(t)?t:[],void(this.i="number"==typeof r?r:4*this.t.length);if(t instanceof n)return this.t=t.words.slice(),void(this.i=t.nSigBytes);var e;try{t instanceof ArrayBuffer?e=new Uint8Array(t):(t instanceof Uint8Array||t instanceof Int8Array||t instanceof Uint8ClampedArray||t instanceof Int16Array||t instanceof Uint16Array||t instanceof Int32Array||t instanceof Uint32Array||t instanceof Float32Array||t instanceof Float64Array)&&(e=new Uint8Array(t.buffer,t.byteOffset,t.byteLength))}catch(n){throw new Error("Invalid argument")}if(!e)throw new Error("Invalid argument");for(var i=e.byteLength,o=[],u=0;u>>2]|=e[u]<<24-u%4*8;this.t=o,this.i=i}return Object.defineProperty(n.prototype,"nSigBytes",{get:function(){return this.i},set:function(n){this.i=n},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"words",{get:function(){return this.t},enumerable:!1,configurable:!0}),n.prototype.toString=function(n){return n?n.stringify(this):e.p.stringify(this)},n.prototype.toUint8Array=function(){for(var n=this.t,t=this.i,r=new Uint8Array(t),e=0;e>>2]>>>24-e%4*8&255;return r},n.prototype.concat=function(n){var t=n.words.slice(),r=n.nSigBytes;if(this.clamp(),this.i%4)for(var e=0;e>>2]>>>24-e%4*8&255;this.t[this.i+e>>>2]|=i<<24-(this.i+e)%4*8}else for(e=0;e>>2]=t[e>>>2];return this.i+=r,this},n.prototype.clamp=function(){var n=this.i;this.t[n>>>2]&=4294967295<<32-n%4*8,this.t.length=Math.ceil(n/4)},n.prototype.clone=function(){return new n(this.t.slice(),this.i)},n.random=function(t){for(var r=[],e=0;e"===n?o>t:">="===n?o>=t:o===t))}},5720:function(n,t,r){r.d(t,{p:function(){return i}});var e=r(3354),i={stringify:function(n){for(var t=n.nSigBytes,r=n.words,e=[],i=0;i>>2]>>>24-i%4*8&255;e.push((o>>>4).toString(16)),e.push((15&o).toString(16))}return e.join("")},parse:function(n){var t=n.length;if(t%2!=0)throw new Error("Hex string count must be even");if(!/^[a-fA-F0-9]+$/.test(n))throw new Error("Invalid Hex string: "+n);for(var r=[],i=0;i>>3]|=parseInt(n.substr(i,2),16)<<24-i%8*4;return new e.e(r,t/2)}}},8702:function(n,t,r){r.d(t,{m:function(){return i}});var e=r(3354),i={stringify:function(n){for(var t=n.nSigBytes,r=n.words,e=[],i=0;i>>2]>>>24-i%4*8&255;e.push(String.fromCharCode(o))}return e.join("")},parse:function(n){for(var t=n.length,r=[],i=0;i>>2]|=(255&n.charCodeAt(i))<<24-i%4*8;return new e.e(r,t)}}},4768:function(n,t,r){r.d(t,{d:function(){return i}});var e=r(8702),i={stringify:function(n){try{return decodeURIComponent(escape(e.m.stringify(n)))}catch(n){throw new Error("Malformed UTF-8 data")}},parse:function(n){return e.m.parse(unescape(encodeURIComponent(n)))}}},9054:function(n,t,e){e.d(t,{M:function(){return o}});var i=e(1756),o=function(){if("undefined"!=typeof window){var n=window.crypto||window.msCrypto;if(!n){if((0,i.w)("<",11))return console.warn("IE <= 10 uses insecure random generator. Please consider to use IE11 or another modern browser"),function(){return Math.floor(512*Math.random())%256};throw new Error("Crypto module not found")}return function(){return n.getRandomValues(new Uint32Array(1))[0]}}return void 0!==e.g&&e.g.crypto?function(){return e.g.crypto.randomBytes(4).readInt32LE()}:function(){return r(845).randomBytes(4).readInt32LE()}}()}},t={};function e(r){var i=t[r];if(void 0!==i)return i.exports;var o=t[r]={exports:{}};return n[r](o,o.exports,e),o.exports}e.d=function(n,t){for(var r in t)e.o(t,r)&&!e.o(n,r)&&Object.defineProperty(n,r,{enumerable:!0,get:t[r]})},e.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(n){if("object"==typeof window)return window}}(),e.o=function(n,t){return Object.prototype.hasOwnProperty.call(n,t)},e.r=function(n){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(n,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(n,"S",{value:!0})};var i={};return function(){e.r(i),e.d(i,{SHA256:function(){return h}});var n,t=e(1868),r=e(3354),o=(n=function(t,r){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,t){n.__proto__=t}||function(n,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(n[r]=t[r])})(t,r)},function(t,r){function e(){this.constructor=t}n(t,r),t.prototype=null===r?Object.create(r):(e.prototype=r.prototype,new e)}),u=[],f=[];function a(n){for(var t=Math.sqrt(n),r=2;r<=t;r++)if(!(n%r))return!1;return!0}function c(n){return 4294967296*(n-(0|n))|0}!function(){for(var n=2,t=0;t<64;)a(n)&&(t<8&&(u[t]=c(Math.pow(n,.5))),f[t]=c(Math.pow(n,1/3)),t++),n++}();var s=[],h=function(n){function t(t){var e=n.call(this,t)||this;return e.N=new r.e(u.slice(0)),e.v=t,t&&void 0!==t.hash&&(e.N=t.hash.clone()),e}return o(t,n),t.prototype.U=function(){this.N=new r.e(u.slice(0))},t.prototype.I=function(n,t){for(var r=this.N.words,e=r[0],i=r[1],o=r[2],u=r[3],a=r[4],c=r[5],h=r[6],l=r[7],w=0;w<64;w++){if(w<16)s[w]=0|n[t+w];else{var v=s[w-15],d=(v<<25|v>>>7)^(v<<14|v>>>18)^v>>>3,y=s[w-2],p=(y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10;s[w]=d+s[w-7]+p+s[w-16]}var b=e&i^e&o^i&o,m=(e<<30|e>>>2)^(e<<19|e>>>13)^(e<<10|e>>>22),g=l+((a<<26|a>>>6)^(a<<21|a>>>11)^(a<<7|a>>>25))+(a&c^~a&h)+f[w]+s[w];l=h,h=c,c=a,a=u+g|0,u=o,o=i,i=e,e=g+(m+b)|0}r[0]=r[0]+e|0,r[1]=r[1]+i|0,r[2]=r[2]+o|0,r[3]=r[3]+u|0,r[4]=r[4]+a|0,r[5]=r[5]+c|0,r[6]=r[6]+h|0,r[7]=r[7]+l|0},t.prototype._=function(){var n=this.l.words,t=8*this.A,r=8*this.l.nSigBytes;return n[r>>>5]|=128<<24-r%32,n[14+(r+64>>>9<<4)]=Math.floor(t/4294967296),n[15+(r+64>>>9<<4)]=t,this.l.nSigBytes=4*n.length,this.O(),this.N},t.prototype.clone=function(){return new t({hash:this.N,blockSize:this.h,data:this.l,nBytes:this.A})},t.hash=function(n,r){return new t(r).finalize(n)},t}(t.P)}(),i}()},699:function(n,t,r){n.exports=function(){"use strict";var n={d:function(t,r){for(var e in r)n.o(r,e)&&!n.o(t,e)&&Object.defineProperty(t,e,{enumerable:!0,get:r[e]})}};n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(n){if("object"==typeof window)return window}}(),n.o=function(n,t){return Object.prototype.hasOwnProperty.call(n,t)},n.r=function(n){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(n,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(n,"t",{value:!0})};var t={};n.r(t),n.d(t,{Utf8:function(){return h}});var e,i=function(n){for(var t=n.nSigBytes,r=n.words,e=[],i=0;i>>2]>>>24-i%4*8&255;e.push((o>>>4).toString(16)),e.push((15&o).toString(16))}return e.join("")},o="undefined"!=typeof navigator&&navigator.userAgent?navigator.userAgent.toLowerCase():"",u=(e=parseInt((/msie (\d+)/.exec(o)||[])[1],10),isNaN(e)?(e=parseInt((/trident\/.*; rv:(\d+)/.exec(o)||[])[1],10),!isNaN(e)&&e):e),f=function(){if("undefined"!=typeof window){var t=window.crypto||window.msCrypto;if(!t){if(function(n,t){return!1!==u&&(!t||("<"===n?u"===n?u>t:">="===n?u>=t:u===t))}("<",11))return console.warn("IE <= 10 uses insecure random generator. Please consider to use IE11 or another modern browser"),function(){return Math.floor(512*Math.random())%256};throw new Error("Crypto module not found")}return function(){return t.getRandomValues(new Uint32Array(1))[0]}}return void 0!==n.g&&n.g.crypto?function(){return n.g.crypto.randomBytes(4).readInt32LE()}:function(){return r(845).randomBytes(4).readInt32LE()}}(),a=function(){function n(t,r){if(Array.isArray(t)||!t)return this.i=Array.isArray(t)?t:[],void(this.u="number"==typeof r?r:4*this.i.length);if(t instanceof n)return this.i=t.words.slice(),void(this.u=t.nSigBytes);var e;try{t instanceof ArrayBuffer?e=new Uint8Array(t):(t instanceof Uint8Array||t instanceof Int8Array||t instanceof Uint8ClampedArray||t instanceof Int16Array||t instanceof Uint16Array||t instanceof Int32Array||t instanceof Uint32Array||t instanceof Float32Array||t instanceof Float64Array)&&(e=new Uint8Array(t.buffer,t.byteOffset,t.byteLength))}catch(n){throw new Error("Invalid argument")}if(!e)throw new Error("Invalid argument");for(var i=e.byteLength,o=[],u=0;u>>2]|=e[u]<<24-u%4*8;this.i=o,this.u=i}return Object.defineProperty(n.prototype,"nSigBytes",{get:function(){return this.u},set:function(n){this.u=n},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"words",{get:function(){return this.i},enumerable:!1,configurable:!0}),n.prototype.toString=function(n){return n?n.stringify(this):i(this)},n.prototype.toUint8Array=function(){for(var n=this.i,t=this.u,r=new Uint8Array(t),e=0;e>>2]>>>24-e%4*8&255;return r},n.prototype.concat=function(n){var t=n.words.slice(),r=n.nSigBytes;if(this.clamp(),this.u%4)for(var e=0;e>>2]>>>24-e%4*8&255;this.i[this.u+e>>>2]|=i<<24-(this.u+e)%4*8}else for(e=0;e>>2]=t[e>>>2];return this.u+=r,this},n.prototype.clamp=function(){var n=this.u;this.i[n>>>2]&=4294967295<<32-n%4*8,this.i.length=Math.ceil(n/4)},n.prototype.clone=function(){return new n(this.i.slice(),this.u)},n.random=function(t){for(var r=[],e=0;e>>2]>>>24-i%4*8&255;e.push(String.fromCharCode(o))}return e.join("")},s=function(n){for(var t=n.length,r=[],e=0;e>>2]|=(255&n.charCodeAt(e))<<24-e%4*8;return new a(r,t)},h={stringify:function(n){try{return decodeURIComponent(escape(c(n)))}catch(n){throw new Error("Malformed UTF-8 data")}},parse:function(n){return s(unescape(encodeURIComponent(n)))}};return t}()},893:function(n,t,r){n.exports=function(){"use strict";var n={d:function(t,r){for(var e in r)n.o(r,e)&&!n.o(t,e)&&Object.defineProperty(t,e,{enumerable:!0,get:r[e]})}};n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(n){if("object"==typeof window)return window}}(),n.o=function(n,t){return Object.prototype.hasOwnProperty.call(n,t)},n.r=function(n){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(n,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(n,"t",{value:!0})};var t={};n.r(t),n.d(t,{Word32Array:function(){return a}});var e,i=function(n){for(var t=n.nSigBytes,r=n.words,e=[],i=0;i>>2]>>>24-i%4*8&255;e.push((o>>>4).toString(16)),e.push((15&o).toString(16))}return e.join("")},o="undefined"!=typeof navigator&&navigator.userAgent?navigator.userAgent.toLowerCase():"",u=(e=parseInt((/msie (\d+)/.exec(o)||[])[1],10),isNaN(e)?(e=parseInt((/trident\/.*; rv:(\d+)/.exec(o)||[])[1],10),!isNaN(e)&&e):e),f=function(){if("undefined"!=typeof window){var t=window.crypto||window.msCrypto;if(!t){if(function(n,t){return!1!==u&&(!t||("<"===n?u"===n?u>t:">="===n?u>=t:u===t))}("<",11))return console.warn("IE <= 10 uses insecure random generator. Please consider to use IE11 or another modern browser"),function(){return Math.floor(512*Math.random())%256};throw new Error("Crypto module not found")}return function(){return t.getRandomValues(new Uint32Array(1))[0]}}return void 0!==n.g&&n.g.crypto?function(){return n.g.crypto.randomBytes(4).readInt32LE()}:function(){return r(845).randomBytes(4).readInt32LE()}}(),a=function(){function n(t,r){if(Array.isArray(t)||!t)return this.i=Array.isArray(t)?t:[],void(this.u="number"==typeof r?r:4*this.i.length);if(t instanceof n)return this.i=t.words.slice(),void(this.u=t.nSigBytes);var e;try{t instanceof ArrayBuffer?e=new Uint8Array(t):(t instanceof Uint8Array||t instanceof Int8Array||t instanceof Uint8ClampedArray||t instanceof Int16Array||t instanceof Uint16Array||t instanceof Int32Array||t instanceof Uint32Array||t instanceof Float32Array||t instanceof Float64Array)&&(e=new Uint8Array(t.buffer,t.byteOffset,t.byteLength))}catch(n){throw new Error("Invalid argument")}if(!e)throw new Error("Invalid argument");for(var i=e.byteLength,o=[],u=0;u>>2]|=e[u]<<24-u%4*8;this.i=o,this.u=i}return Object.defineProperty(n.prototype,"nSigBytes",{get:function(){return this.u},set:function(n){this.u=n},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"words",{get:function(){return this.i},enumerable:!1,configurable:!0}),n.prototype.toString=function(n){return n?n.stringify(this):i(this)},n.prototype.toUint8Array=function(){for(var n=this.i,t=this.u,r=new Uint8Array(t),e=0;e>>2]>>>24-e%4*8&255;return r},n.prototype.concat=function(n){var t=n.words.slice(),r=n.nSigBytes;if(this.clamp(),this.u%4)for(var e=0;e>>2]>>>24-e%4*8&255;this.i[this.u+e>>>2]|=i<<24-(this.u+e)%4*8}else for(e=0;e>>2]=t[e>>>2];return this.u+=r,this},n.prototype.clamp=function(){var n=this.u;this.i[n>>>2]&=4294967295<<32-n%4*8,this.i.length=Math.ceil(n/4)},n.prototype.clone=function(){return new n(this.i.slice(),this.u)},n.random=function(t){for(var r=[],e=0;e0)throw new Error(`can't cast ${JSON.stringify(n)} to bytes`);return o.Bytes.NULL}if("function"==typeof n.serialize)return o.Bytes.from(n,"G1Element");throw new Error(`can't cast ${JSON.stringify(n)} to bytes`)}function l(n){let t=n;const r=[t],u=[o.t(0,e.None)];for(;u.length;){const n=u.pop(),f=n[0];let a=n[1];if(0!==f){if(null===a)throw new Error("Invalid target. target is null");1===f?r[a].pair=o.t(new i.CLVMObject(r.pop()),r[a].pair[1]):2===f?r[a].pair=o.t(r[a].pair[0],new i.CLVMObject(r.pop())):3===f&&(r[a]=new i.CLVMObject(o.t(r.pop(),r[a])))}else{if(s(r[r.length-1]))continue;if(t=r.pop(),o.isTuple(t)){if(2!==t.length)throw new Error(`can't cast tuple of size ${t.length}`);const[n,f]=t;a=r.length,r.push(new i.CLVMObject(o.t(n,f))),s(f)||(r.push(f),u.push(o.t(2,a)),u.push(o.t(0,e.None))),s(n)||(r.push(n),u.push(o.t(1,a)),u.push(o.t(0,e.None)));continue}if(Array.isArray(t)){a=r.length,r.push(new i.CLVMObject(o.Bytes.NULL));for(const n of t)r.push(n),u.push(o.t(3,a)),s(n)||u.push(o.t(0,e.None));continue}r.push(new i.CLVMObject(h(t)))}}if(1!==r.length)throw new Error("internal error");return r[0]}t.looks_like_clvm_object=s,t.convert_atom_to_bytes=h,t.to_sexp_type=l;class w{constructor(n){this.atom=e.None,this.pair=e.None,this.atom=n.atom,this.pair=n.pair}static to(n){return v(n)?n:s(n)?new w(n):new w(l(n))}static null(){return w.an}as_pair(){const n=this.pair;return n===e.None?n:o.t(new w(n[0]),new w(n[1]))}listp(){return this.pair!==e.None}nullp(){return this.atom!==e.None&&0===this.atom.raw().length}as_int(){return u.int_from_bytes(this.atom)}as_bin(){const n=new o.Stream;return f.sexp_to_stream(this,n),n.getValue()}cons(n){return w.to(o.t(this,n))}first(){const n=this.pair;if(n)return new w(n[0]);throw new c.EvalError("first of non-cons",this)}rest(){const n=this.pair;if(n)return new w(n[1]);throw new c.EvalError("rest of non-cons",this)}*as_iter(){let n=this;for(;!n.nullp();)yield n.first(),n=n.rest()}equal_to(n){try{n=w.to(n);const t=[o.t(this,n)];for(;t.length;){const[n,r]=t.pop(),e=n.as_pair();if(e){const n=r.as_pair();if(!n)return!1;t.push(o.t(e[0],n[0])),t.push(o.t(e[1],n[1]))}else if(r.as_pair()||!(n.atom&&r.atom&&n.atom.equal_to(r.atom)))return!1}return!0}catch(n){return!1}}list_len(){let n=this,t=0;for(;n.listp();)t+=1,n=n.rest();return t}as_javascript(){return a.as_javascript(this)}toString(){return this.as_bin().hex()}cn(){return`SExp(${this.as_bin().hex()})`}}function v(n){return n&&void 0!==n.atom&&void 0!==n.pair&&"function"==typeof n.first&&"function"==typeof n.rest&&"function"==typeof n.cons}t.SExp=w,w.TRUE=new w(new i.CLVMObject(o.Bytes.from("0x01","hex"))),w.FALSE=new w(new i.CLVMObject(o.Bytes.NULL)),w.an=new w(new i.CLVMObject(o.Bytes.NULL)),t.isSExp=v},190:function(n,t,r){"use strict";var e=this&&this.sn||function(n,t,r,e){return new(r||(r=Promise))((function(i,o){function u(n){try{a(e.next(n))}catch(n){o(n)}}function f(n){try{a(e.throw(n))}catch(n){o(n)}}function a(n){var t;n.done?i(n.value):(t=n.value,t instanceof r?t:new r((function(n){n(t)}))).then(u,f)}a((e=e.apply(n,t||[])).next())}))};Object.defineProperty(t,"un",{value:!0}),t.G1Element_add=t.assert_G1Element_valid=t.G1Element_from_bytes=t.getBLSModule=t.initializeBLS=t.loadPromise=t.BLS=void 0;const i=r(513);function o(){if(!t.BLS)throw new Error("BLS module has not been loaded. Please call `await initializeBLS()` on start up");return t.BLS}function u(n){const t=o(),{G1Element:r}=t;if(n.length!==r.SIZE)throw new Error("G1Element: Invalid size");if(192==(192&n[0])){if(192!==n[0])throw new Error("G1Element: Given G1 infinity element must be canonical");for(let t=1;t{if(t.BLS)return t.loadPromise=void 0,n(t.BLS);i().then((e=>e?(t.loadPromise=void 0,n(t.BLS=e)):r())).catch((n=>(console.error("Error while loading BLS module"),r(n))))}))}))},t.getBLSModule=o,t.G1Element_from_bytes=function(n){u(n);const t=o();try{return t.G1Element.from_bytes(n)}catch(n){throw new Error("Exception in G1Element operation")}},t.assert_G1Element_valid=u,t.G1Element_add=function(n,t){try{return n.add(t)}catch(n){throw new Error("Exception in G1Element operation")}}},572:function(n,t,r){"use strict";Object.defineProperty(t,"un",{value:!0}),t.prettyPrint=void 0;const e=r(907);t.prettyPrint=function(n){if(n){const n=e.SExp.prototype.toString;e.SExp.prototype.toString=e.SExp.prototype.cn,e.SExp.prototype.cn=n}else{const n=e.SExp.prototype.toString;e.SExp.prototype.toString=e.SExp.prototype.cn,e.SExp.prototype.cn=n}}},213:function(n,t){"use strict";Object.defineProperty(t,"un",{value:!0}),t.None=void 0,t.None=null},593:function(n,t,r){"use strict";Object.defineProperty(t,"un",{value:!0}),t.Stream=t.isBytes=t.isIterable=t.isList=t.isTuple=t.t=t.Tuple=t.list=t.h=t.b=t.Bytes=t.PyBytes_Repr=t.to_hexstr=void 0;const e=r(502),i=r(699),o=r(893),u=r(915),f=r(213);function a(n){return new o.Word32Array(n).toString()}function c(n){let t=0,r=0;for(let e=0;e=127?(i+="\\x",i+=r.toString(16).padStart(2,"0")):i+=o}return i+=e,i}t.to_hexstr=a,t.PyBytes_Repr=c;class s{constructor(n){if(n instanceof Uint8Array)this.hn=n;else if(w(n))this.hn=n.raw();else{if(n&&n!==f.None)throw new Error(`Invalid value: ${JSON.stringify(n)}`);this.hn=new Uint8Array}}static from(n,t){if(n===f.None||void 0===n)return new s(n);if(n instanceof Uint8Array)return new s(n.slice());if(w(n))return new s(n.data());if(Array.isArray(n)&&n.every((n=>"number"==typeof n))){if(n.some((n=>n<0||n>255)))throw new Error("Bytes must be in range [0, 256)");return new s(Uint8Array.from(n))}if("string"==typeof n)return"hex"===t?(n=n.replace(/^0x/,""),new s(e.Hex.parse(n).toUint8Array())):new s(i.Utf8.parse(n).toUint8Array());if("G1Element"===t){if("function"!=typeof n.serialize)throw new Error("Invalid G1Element");const t=n.serialize();return new s(t)}throw new Error(`Invalid value: ${JSON.stringify(n)}`)}static SHA256(n){let t;if("string"==typeof n)t=u.SHA256.hash(n);else if(n instanceof Uint8Array)t=new o.Word32Array(n),t=u.SHA256.hash(t);else{if(!w(n))throw new Error("Invalid argument");t=n.as_word(),t=u.SHA256.hash(t)}return new s(t.toUint8Array())}get length(){return this.hn.length}get_byte_at(n){return 0|this.hn[n]}concat(n){const t=this.hn,r=n.raw(),e=new Uint8Array(t.length+r.length);return e.set(t,0),e.set(r,t.length),new s(e)}repeat(n){const t=new Uint8Array(this.length*n);for(let r=0;rn.length?1:-1;const t=new DataView(this.raw().buffer),r=new DataView(n.raw().buffer),e=this.length/4|0;for(let n=0;ni?1:-1}for(let n=4*e;ni?1:-1}return 0}}t.Bytes=s,s.NULL=new s,t.b=function(n,t="utf8"){return s.from(n,t)},t.h=function(n){return s.from(n,"hex")},t.list=function(n){const t=[];for(const r of n)t.push(r);return t};class h extends Array{constructor(...n){return super(...n),Object.freeze(this),this}toString(){return`(${this[0]}, ${this[1]})`}}function l(n){return n instanceof Array&&Object.isFrozen(n)&&2===n.length}function w(n){return n&&"number"==typeof n.length&&"function"==typeof n.get_byte_at&&"function"==typeof n.raw&&"function"==typeof n.data&&"function"==typeof n.hex&&"function"==typeof n.decode&&"function"==typeof n.equal_to&&"function"==typeof n.compare}t.Tuple=h,t.t=function(n,t){return new h(n,t)},t.isTuple=l,t.isList=function(n){return Array.isArray(n)&&!l(n)},t.isIterable=function(n){return!!Array.isArray(n)||"string"!=typeof n&&"function"==typeof n[Symbol.iterator]},t.isBytes=w;class v{constructor(n){this.ln=4,this.wn=0,n?(n.length>v.INITIAL_BUFFER_SIZE?this.vn=new Uint8Array(2*n.length):this.vn=new Uint8Array(v.INITIAL_BUFFER_SIZE),this.vn.set(n.raw()),this.dn=n.length):(this.vn=new Uint8Array(v.INITIAL_BUFFER_SIZE),this.dn=0)}get seek(){return this.wn}set seek(n){n<0?this.wn=this.length-1:n>this.length-1?this.wn=this.length:this.wn=n}get length(){return this.dn}reAllocate(n){let t="number"==typeof n?n:this.vn.length*this.ln;t>4294967295&&(t=4294967295);const r=new Uint8Array(t);r.set(this.vn),this.vn=r}write(n){const t=Math.max(this.length,n.length+this.wn);t>this.vn.length&&this.reAllocate(t*this.ln);const r=this.seek;return this.vn.set(n.raw(),r),this.dn=t,this.seek+=n.length,n.length}read(n){if(this.seek>this.length-1)return new s;if(this.seek+n<=this.length){const t=this.vn.slice(this.seek,this.seek+n);return this.seek+=n,new s(t)}const t=new Uint8Array(this.length-this.seek);return t.set(this.vn.subarray(this.seek,this.length)),this.seek+=n,new s(t)}getValue(){return new s(this.vn.subarray(0,this.length))}}t.Stream=v,v.INITIAL_BUFFER_SIZE=65536},19:function(n,t,r){"use strict";Object.defineProperty(t,"un",{value:!0}),t.as_javascript=void 0;const e=r(593);t.as_javascript=function(n){function t(n,t){const r=t.pop(),e=t.pop();t.push(r),t.push(e)}function r(n,t){const r=t.pop(),i=t.pop();i.equal_to(e.Bytes.NULL)?t.push([r]):t.push(e.t(r,i))}function i(n,t){let r=[t.pop()];const e=t.pop();r=r.concat(e),t.push(r)}const o=[function n(e,o){const u=o.pop(),f=u.as_pair();if(f){const[u,a]=f;a.listp()?e.push(i):e.push(r),e.push(n),e.push(t),e.push(n),o.push(u),o.push(a)}else o.push(u.atom)}],u=[n];for(;o.length;){const n=o.pop();n&&n(o,u)}return u[u.length-1]}},959:function(n,t,r){"use strict";Object.defineProperty(t,"un",{value:!0}),t.limbs_for_int=t.int_to_bytes=t.int_from_bytes=void 0;const e=r(593);t.int_from_bytes=function(n){if(!n||0===n.length)return 0;const t=parseInt(n.hex(),16);return 128&n.get_byte_at(0)?t-(1<<8*n.length):t},t.int_to_bytes=function(n){if(n>Number.MAX_SAFE_INTEGER||n0?"MAX_SAFE_INTEGER":"MIN_SAFE_INTEGER"}: ${n}`);if(0===n)return e.Bytes.NULL;const t=(n<0?-n:n).toString(2).length+8>>3;let r=(n>>>0).toString(16);for(n>=0&&(r=r.length%2?`0${r}`:r);r.length/22&&r.substr(0,2)===(128&parseInt(r.substr(2,2),16)?"ff":"00");)r=r.substr(2);return e.h(r)},t.limbs_for_int=function(n){return(n<0?-n:n).toString(2).length+7>>3}},143:function(n,t,r){"use strict";Object.defineProperty(t,"un",{value:!0}),t.op_eq=t.op_raise=t.op_listp=t.op_rest=t.op_first=t.op_cons=t.op_if=void 0;const e=r(907),i=r(593),o=r(449),u=r(755);t.op_if=function(n){if(3!==n.list_len())throw new u.EvalError("i takes exactly 3 arguments",n);const t=n.rest();return n.first().nullp()?i.t(o.IF_COST,t.rest().first()):i.t(o.IF_COST,t.first())},t.op_cons=function(n){if(2!==n.list_len())throw new u.EvalError("c takes exactly 2 arguments",n);return i.t(o.CONS_COST,n.first().cons(n.rest().first()))},t.op_first=function(n){if(1!==n.list_len())throw new u.EvalError("f takes exactly 1 argument",n);return i.t(o.FIRST_COST,n.first().first())},t.op_rest=function(n){if(1!==n.list_len())throw new u.EvalError("r takes exactly 1 argument",n);return i.t(o.REST_COST,n.first().rest())},t.op_listp=function(n){if(1!==n.list_len())throw new u.EvalError("l takes exactly 1 argument",n);return i.t(o.LISTP_COST,n.first().listp()?e.SExp.TRUE:e.SExp.FALSE)},t.op_raise=function(n){throw new u.EvalError("clvm raise",n)},t.op_eq=function(n){if(2!==n.list_len())throw new u.EvalError("= takes exactly 2 arguments",n);const t=n.first(),r=n.rest().first();if(t.pair||r.pair)throw new u.EvalError("= on list",t.pair?t:r);const f=t.atom,a=r.atom;let c=o.EQ_BASE_COST;return c+=(f.length+a.length)*o.EQ_COST_PER_BYTE,i.t(c,f.equal_to(a)?e.SExp.TRUE:e.SExp.FALSE)}},449:function(n,t){"use strict";Object.defineProperty(t,"un",{value:!0}),t.APPLY_COST=t.LOGNOT_COST_PER_BYTE=t.LOGNOT_BASE_COST=t.LSHIFT_COST_PER_BYTE=t.LSHIFT_BASE_COST=t.ASHIFT_COST_PER_BYTE=t.ASHIFT_BASE_COST=t.BOOL_COST_PER_ARG=t.BOOL_BASE_COST=t.CONCAT_COST_PER_BYTE=t.CONCAT_COST_PER_ARG=t.CONCAT_BASE_COST=t.PATH_LOOKUP_COST_PER_ZERO_BYTE=t.PATH_LOOKUP_COST_PER_LEG=t.PATH_LOOKUP_BASE_COST=t.STRLEN_COST_PER_BYTE=t.STRLEN_BASE_COST=t.MUL_SQUARE_COST_PER_BYTE_DIVIDER=t.MUL_LINEAR_COST_PER_BYTE=t.MUL_COST_PER_OP=t.MUL_BASE_COST=t.PUBKEY_COST_PER_BYTE=t.PUBKEY_BASE_COST=t.POINT_ADD_COST_PER_ARG=t.POINT_ADD_BASE_COST=t.SHA256_COST_PER_BYTE=t.SHA256_COST_PER_ARG=t.SHA256_BASE_COST=t.DIV_COST_PER_BYTE=t.DIV_BASE_COST=t.DIVMOD_COST_PER_BYTE=t.DIVMOD_BASE_COST=t.GR_COST_PER_BYTE=t.GR_BASE_COST=t.EQ_COST_PER_BYTE=t.EQ_BASE_COST=t.GRS_COST_PER_BYTE=t.GRS_BASE_COST=t.LOG_COST_PER_ARG=t.LOG_COST_PER_BYTE=t.LOG_BASE_COST=t.ARITH_COST_PER_ARG=t.ARITH_COST_PER_BYTE=t.ARITH_BASE_COST=t.MALLOC_COST_PER_BYTE=t.LISTP_COST=t.REST_COST=t.FIRST_COST=t.CONS_COST=t.IF_COST=void 0,t.QUOTE_COST=void 0,t.IF_COST=33,t.CONS_COST=50,t.FIRST_COST=30,t.REST_COST=30,t.LISTP_COST=19,t.MALLOC_COST_PER_BYTE=10,t.ARITH_BASE_COST=99,t.ARITH_COST_PER_BYTE=3,t.ARITH_COST_PER_ARG=320,t.LOG_BASE_COST=100,t.LOG_COST_PER_BYTE=3,t.LOG_COST_PER_ARG=264,t.GRS_BASE_COST=117,t.GRS_COST_PER_BYTE=1,t.EQ_BASE_COST=117,t.EQ_COST_PER_BYTE=1,t.GR_BASE_COST=498,t.GR_COST_PER_BYTE=2,t.DIVMOD_BASE_COST=1116,t.DIVMOD_COST_PER_BYTE=6,t.DIV_BASE_COST=988,t.DIV_COST_PER_BYTE=4,t.SHA256_BASE_COST=87,t.SHA256_COST_PER_ARG=134,t.SHA256_COST_PER_BYTE=2,t.POINT_ADD_BASE_COST=101094,t.POINT_ADD_COST_PER_ARG=1343980,t.PUBKEY_BASE_COST=1325730,t.PUBKEY_COST_PER_BYTE=38,t.MUL_BASE_COST=92,t.MUL_COST_PER_OP=885,t.MUL_LINEAR_COST_PER_BYTE=6,t.MUL_SQUARE_COST_PER_BYTE_DIVIDER=128,t.STRLEN_BASE_COST=173,t.STRLEN_COST_PER_BYTE=1,t.PATH_LOOKUP_BASE_COST=40,t.PATH_LOOKUP_COST_PER_LEG=4,t.PATH_LOOKUP_COST_PER_ZERO_BYTE=4,t.CONCAT_BASE_COST=142,t.CONCAT_COST_PER_ARG=135,t.CONCAT_COST_PER_BYTE=3,t.BOOL_BASE_COST=200,t.BOOL_COST_PER_ARG=300,t.ASHIFT_BASE_COST=596,t.ASHIFT_COST_PER_BYTE=3,t.LSHIFT_BASE_COST=277,t.LSHIFT_COST_PER_BYTE=3,t.LOGNOT_BASE_COST=331,t.LOGNOT_COST_PER_BYTE=3,t.APPLY_COST=90,t.QUOTE_COST=20},465:function(n,t,r){"use strict";var e=this&&this.yn||(Object.create?function(n,t,r,e){void 0===e&&(e=r),Object.defineProperty(n,e,{enumerable:!0,get:function(){return t[r]}})}:function(n,t,r,e){void 0===e&&(e=r),n[e]=t[r]}),i=this&&this.pn||function(n,t){for(var r in n)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||e(t,n,r)};Object.defineProperty(t,"un",{value:!0}),t.to_sexp_f=void 0;const o=r(907);i(r(572),t),i(r(190),t),i(r(213),t),i(r(593),t),i(r(19),t),i(r(959),t),i(r(629),t),i(r(143),t),i(r(449),t),i(r(755),t),i(r(419),t),i(r(601),t),i(r(637),t),i(r(990),t),i(r(282),t),i(r(351),t),i(r(907),t),t.to_sexp_f=o.SExp.to},419:function(n,t,r){"use strict";var e=this&&this.sn||function(n,t,r,e){return new(r||(r=Promise))((function(i,o){function u(n){try{a(e.next(n))}catch(n){o(n)}}function f(n){try{a(e.throw(n))}catch(n){o(n)}}function a(n){var t;n.done?i(n.value):(t=n.value,t instanceof r?t:new r((function(n){n(t)}))).then(u,f)}a((e=e.apply(n,t||[])).next())}))};Object.defineProperty(t,"un",{value:!0}),t.initialize=void 0;const i=r(190);t.initialize=function(){return e(this,void 0,void 0,(function*(){yield i.initializeBLS()}))}},601:function(n,t,r){"use strict";Object.defineProperty(t,"un",{value:!0}),t.op_softfork=t.op_all=t.op_any=t.op_not=t.op_lognot=t.op_logxor=t.op_logior=t.op_logand=t.binop_reduction=t.op_lsh=t.op_ash=t.op_concat=t.op_substr=t.op_strlen=t.op_pubkey_for_exp=t.op_gr_bytes=t.op_gr=t.op_div=t.op_divmod=t.op_multiply=t.op_subtract=t.op_add=t.args_as_bool_list=t.args_as_bools=t.args_as_int_list=t.args_as_int32=t.args_as_ints=t.op_sha256=t.malloc_cost=void 0;const e=r(915),i=r(907),o=r(449),u=r(593),f=r(755),a=r(959),c=r(629),s=r(190);function h(n,t){if(!t.atom)throw new f.EvalError("atom is None",t);return u.t(n+t.atom.length*o.MALLOC_COST_PER_BYTE,t)}function*l(n,t){for(const r of t.as_iter()){if(r.pair||!r.atom)throw new f.EvalError(`${n} requires int args`,r);yield u.t(r.as_int(),r.atom.length)}}function*w(n,t){for(const r of t.as_iter()){if(r.pair||!r.atom)throw new f.EvalError(`${n} requires int32 args`,r);if(r.atom.length>4)throw new f.EvalError(`${n} requires int32 args (with no leading zeros`,r);yield r.as_int()}}function v(n,t,r){const e=[];for(const r of l(n,t))e.push(r);if(e.length!==r){const e=1!==r?"s":"";throw new f.EvalError(`${n} takes exactly ${r} argument${e}`,t)}return e}function*d(n,t){for(const n of t.as_iter()){const t=n.atom;(null==t?void 0:t.equal_to(u.Bytes.NULL))?yield i.SExp.FALSE:yield i.SExp.TRUE}}function y(n,t,r){const e=[];for(const n of d(0,t))e.push(n);if(e.length!==r){const e=1!==r?"s":"";throw new f.EvalError(`${n} takes exactly ${r} argument${e}`,t)}return e}function p(n,t,r,e){let u=t,f=0,a=o.LOG_BASE_COST;for(const t of l(n,r)){const[n,r]=t;u=e(u,n),f+=r,a+=o.LOG_COST_PER_ARG}return a+=f*o.LOG_COST_PER_BYTE,h(a,i.SExp.to(u))}t.malloc_cost=h,t.op_sha256=function(n){let t=o.SHA256_BASE_COST,r=0;const a=new e.SHA256;for(const e of n.as_iter()){const n=e.atom;if(!n)throw new f.EvalError("sha256 on list",e);r+=n.length,t+=o.SHA256_COST_PER_ARG,a.update(n.as_word())}return t+=r*o.SHA256_COST_PER_BYTE,h(t,i.SExp.to(u.Bytes.from(a.finalize().toUint8Array())))},t.args_as_ints=l,t.args_as_int32=w,t.args_as_int_list=v,t.args_as_bools=d,t.args_as_bool_list=y,t.op_add=function(n){let t=0,r=o.ARITH_BASE_COST,e=0;for(const i of l("+",n)){const[n,u]=i;t+=n,e+=u,r+=o.ARITH_COST_PER_ARG}return r+=e*o.ARITH_COST_PER_BYTE,h(r,i.SExp.to(t))},t.op_subtract=function(n){let t=o.ARITH_BASE_COST;if(n.nullp())return h(t,i.SExp.to(0));let r=1,e=0,u=0;for(const i of l("-",n)){const[n,f]=i;e+=r*n,r=-1,u+=f,t+=o.ARITH_COST_PER_BYTE}return t+=u*o.ARITH_COST_PER_BYTE,h(t,i.SExp.to(e))},t.op_multiply=function(n){let t=o.MUL_BASE_COST;const r=l("*",n),e=r.next();if(e.done)return h(t,i.SExp.to(1));let[u,f]=e.value;for(const n of r){const[r,e]=n;t+=o.MUL_COST_PER_OP,t+=(e+f)*o.MUL_LINEAR_COST_PER_BYTE,t+=e*f/o.MUL_SQUARE_COST_PER_BYTE_DIVIDER>>0,u*=r,f=a.limbs_for_int(u)}return h(t,i.SExp.to(u))},t.op_divmod=function(n){let t=o.DIVMOD_BASE_COST;const[r,e]=v("divmod",n,2),[a,c]=r,[s,h]=e;if(0===s)throw new f.EvalError("divmod with 0",i.SExp.to(a));t+=(c+h)*o.DIVMOD_COST_PER_BYTE;const l=a/s>>0,w=a%s,d=i.SExp.to(l),y=i.SExp.to(w);return t+=(d.atom.length+y.atom.length)*o.MALLOC_COST_PER_BYTE,u.t(t,i.SExp.to(u.t(l,w)))},t.op_div=function(n){let t=o.DIV_BASE_COST;const[r,e]=v("/",n,2),[u,a]=r,[c,s]=e;if(0===c)throw new f.EvalError("div with 0",i.SExp.to(u));t+=(a+s)*o.DIV_COST_PER_BYTE;const l=u/c>>0;return h(t,i.SExp.to(l))},t.op_gr=function(n){const[t,r]=v(">",n,2),[e,f]=t,[a,c]=r;let s=o.GR_BASE_COST;return s+=(f+c)*o.GR_COST_PER_BYTE,u.t(s,e>a?i.SExp.TRUE:i.SExp.FALSE)},t.op_gr_bytes=function(n){const t=[];for(const r of n.as_iter())t.push(r);if(2!==t.length)throw new f.EvalError(">s takes exactly 2 arguments",n);const[r,e]=t;if(r.pair||e.pair)throw new f.EvalError(">s on list",r.pair?r:e);const a=r.atom,c=e.atom;let s=o.GRS_BASE_COST;return s+=(a.length+c.length)*o.GRS_COST_PER_BYTE,u.t(s,a.compare(c)>0?i.SExp.TRUE:i.SExp.FALSE)},t.op_pubkey_for_exp=function(n){let t=o.POINT_ADD_BASE_COST;const{G1Element:r}=s.getBLSModule();let e=new r;for(const r of n.as_iter()){if(!c.isAtom(r))throw new f.EvalError("point_add on list",r);try{const n=s.G1Element_from_bytes(r.atom.data());e=s.G1Element_add(e,n),t+=o.POINT_ADD_COST_PER_ARG}catch(t){throw new f.EvalError(`point_add expects blob, got ${r.atom}: ${JSON.stringify(t)}`,n)}}return h(t,i.SExp.to(e))},t.op_strlen=function(n){if(1!==n.list_len())throw new f.EvalError("strlen takes exactly 1 argument",n);const t=n.first();if(!c.isAtom(t))throw new f.EvalError("strlen on list",t);const r=t.atom.length;return h(o.STRLEN_BASE_COST+r*o.STRLEN_COST_PER_BYTE,i.SExp.to(r))},t.op_substr=function(n){const t=n.list_len();if(![2,3].includes(t))throw new f.EvalError("substr takes exactly 2 or 3 arguments",n);const r=n.first();if(!c.isAtom(r))throw new f.EvalError("substr on list",r);const e=r.atom;let o,a;if(2===t)o=w("substr",n.rest()).next().value,a=e.length;else{const t=[];for(const r of w("substr",n.rest()))t.push(r);[o,a]=t}if(a>e.length||a4)throw new f.EvalError("ash requires int32 args (with no leading zeros)",n.rest().first());if(Math.abs(c)>65535)throw new f.EvalError("shift too large",i.SExp.to(c));let l;l=c>=0?e<>-c;let w=o.ASHIFT_BASE_COST;return w+=(u+a.limbs_for_int(l))*o.ASHIFT_COST_PER_BYTE,h(w,i.SExp.to(l))},t.op_lsh=function(n){const[t,r]=v("lsh",n,2),e=t[1],[u,c]=r;if(c>4)throw new f.EvalError("lsh requires int32 args (with no leading zeros)",n.rest().first());if(Math.abs(u)>65535)throw new f.EvalError("shift too large",i.SExp.to(u));const s=n.first().atom,l=a.int_from_bytes(s);let w;w=u>=0?l<>-u;let d=o.LSHIFT_BASE_COST;return d+=(e+a.limbs_for_int(w))*o.LSHIFT_COST_PER_BYTE,h(d,i.SExp.to(w))},t.binop_reduction=p,t.op_logand=function(n){return p("logand",-1,n,((n,t)=>n&=t))},t.op_logior=function(n){return p("logior",0,n,((n,t)=>n|=t))},t.op_logxor=function(n){return p("logxor",0,n,((n,t)=>n^=t))},t.op_lognot=function(n){const t=v("lognot",n,1),[r,e]=t[0];return h(o.LOGNOT_BASE_COST+e*o.LOGNOT_COST_PER_BYTE,i.SExp.to(~r))},t.op_not=function(n){const t=y("not",n,1)[0];if(!c.isAtom(t))throw new f.EvalError("not on list",n);let r;return r=t.atom.equal_to(u.Bytes.NULL)?i.SExp.TRUE:i.SExp.FALSE,u.t(o.BOOL_BASE_COST,i.SExp.to(r))},t.op_any=function(n){const t=[];for(const r of d(0,n))t.push(r);const r=o.BOOL_BASE_COST+t.length*o.BOOL_COST_PER_ARG;let e=i.SExp.FALSE;for(const r of t){if(!c.isAtom(r))throw new f.EvalError("any on list",n);if(!r.atom.equal_to(u.Bytes.NULL)){e=i.SExp.TRUE;break}}return u.t(r,i.SExp.to(e))},t.op_all=function(n){const t=[];for(const r of d(0,n))t.push(r);const r=o.BOOL_BASE_COST+t.length*o.BOOL_COST_PER_ARG;let e=i.SExp.TRUE;for(const r of t){if(!c.isAtom(r))throw new f.EvalError("all on list",n);if(r.atom.equal_to(u.Bytes.NULL)){e=i.SExp.FALSE;break}}return u.t(r,i.SExp.to(e))},t.op_softfork=function(n){if(n.list_len()<1)throw new f.EvalError("softfork takes at least 1 argument",n);const t=n.first();if(!c.isAtom(t))throw new f.EvalError("softfork requires int args",t);const r=t.as_int();if(r<1)throw new f.EvalError("cost must be > 0",n);return u.t(r,i.SExp.FALSE)}},637:function(n,t){"use strict";function r(n,t,r){const e={};for(const i of Object.keys(n)){const o=t[`op_${r[i]||i}`];"function"==typeof o&&(e[n[i]]=o)}return e}Object.defineProperty(t,"un",{value:!0}),t.operators_for_module=t.operators_for_dict=void 0,t.operators_for_dict=r,t.operators_for_module=function(n,t,e={}){return r(n,t,e)}},990:function(n,t,r){"use strict";Object.defineProperty(t,"un",{value:!0}),t.OPERATOR_LOOKUP=t.OperatorDict=t.APPLY_ATOM=t.QUOTE_ATOM=t.default_unknown_op=t.args_len=t.OP_REWRITE=t.KEYWORD_TO_ATOM=t.KEYWORD_FROM_ATOM=void 0;const e=r(959),i=r(907),o=r(593),u=r(755),f=r(449),a=r(637),c=r(143),s=r(601);function*h(n,t){for(const r of t.as_iter()){if(r.pair)throw new u.EvalError(`${n} requires int args"`,r);yield r.atom.length}}function l(n,t){if(0===n.length||n.slice(0,2).equal_to(o.Bytes.from("0xffff","hex")))throw new u.EvalError("reserved operator",i.SExp.to(n));const r=(192&n.get_byte_at(n.length-1))>>6;if(n.length>5)throw new u.EvalError("invalid operator",i.SExp.to(n));const a=e.int_from_bytes(n.slice(0,n.length-1))+1;let c;if(0===r)c=1;else if(1===r){c=f.ARITH_BASE_COST;let n=0;for(const r of h("unknown op",t))n+=r,c+=f.ARITH_COST_PER_ARG;c+=n*f.ARITH_COST_PER_BYTE}else if(2===r){c=f.MUL_BASE_COST;const n=h("unknown op",t),r=n.next();if(!r.done){let t=r.value;for(const r of n)c+=f.MUL_COST_PER_OP,c+=(r+t)*f.MUL_LINEAR_COST_PER_BYTE,c+=r*t/f.MUL_SQUARE_COST_PER_BYTE_DIVIDER>>0,t+=r}}else{if(3!==r)throw new Error(`Invalid cost_function: ${r}`);{c=f.CONCAT_BASE_COST;let n=0;for(const r of t.as_iter()){if(r.pair)throw new u.EvalError("unknown op on list",r);c+=f.CONCAT_COST_PER_ARG,n+=r.atom.length}c+=n*f.CONCAT_COST_PER_BYTE}}if(c*=a,c>=2**32)throw new u.EvalError("invalid operator",i.SExp.to(n));return o.t(c,i.SExp.null())}function w(n,t){Object.keys(t).forEach((r=>{n[r]=t[r]}))}function v(n,t={}){const r=Object.assign(Object.assign({},n),{quote_atom:t.quote_atom||n.quote_atom,apply_atom:t.apply_atom||n.apply_atom,unknown_op_handler:t.unknown_op_handler||l});if(!r.quote_atom)throw new Error("object has not attribute 'quote_atom'");if(!r.apply_atom)throw new Error("object has not attribute 'apply_atom'");const e=function(n,t){if("string"==typeof n)n=o.Bytes.from(n,"hex");else if("number"==typeof n)n=o.Bytes.from([n]);else if(!o.isBytes(n))throw new Error(`Invalid op: ${JSON.stringify(n)}`);w(r,e);const i=r[n.hex()];return"function"!=typeof i?r.unknown_op_handler(n,t):i(t)};return w(e,r),e}t.KEYWORD_FROM_ATOM={"00":".","01":"q","02":"a","03":"i","04":"c","05":"f","06":"r","07":"l","08":"x","09":"=","0a":">s","0b":"sha256","0c":"substr","0d":"strlen","0e":"concat","0f":".",10:"+",11:"-",12:"*",13:"/",14:"divmod",15:">",16:"ash",17:"lsh",18:"logand",19:"logior","1a":"logxor","1b":"lognot","1c":".","1d":"point_add","1e":"pubkey_for_exp","1f":".",20:"not",21:"any",22:"all",23:".",24:"softfork"},t.KEYWORD_TO_ATOM={q:"01",a:"02",i:"03",c:"04",f:"05",r:"06",l:"07",x:"08","=":"09",">s":"0a",sha256:"0b",substr:"0c",strlen:"0d",concat:"0e","+":"10","-":"11","*":"12","/":"13",divmod:"14",">":"15",ash:"16",lsh:"17",logand:"18",logior:"19",logxor:"1a",lognot:"1b",point_add:"1d",pubkey_for_exp:"1e",not:"20",any:"21",all:"22",".":"23",softfork:"24"},t.OP_REWRITE={"+":"add","-":"subtract","*":"multiply","/":"div",i:"if",c:"cons",f:"first",r:"rest",l:"listp",x:"raise","=":"eq",">":"gr",">s":"gr_bytes"},t.args_len=h,t.default_unknown_op=l,t.QUOTE_ATOM=o.Bytes.from(t.KEYWORD_TO_ATOM.q,"hex"),t.APPLY_ATOM=o.Bytes.from(t.KEYWORD_TO_ATOM.a,"hex"),t.OperatorDict=v;const d=v(a.operators_for_module(t.KEYWORD_TO_ATOM,c,t.OP_REWRITE),{quote_atom:t.QUOTE_ATOM,apply_atom:t.APPLY_ATOM});w(d,a.operators_for_module(t.KEYWORD_TO_ATOM,s,t.OP_REWRITE)),t.OPERATOR_LOOKUP=d},282:function(n,t,r){"use strict";Object.defineProperty(t,"un",{value:!0}),t.run_program=t.msb_mask=t.to_pre_eval_op=void 0;const e=r(213),i=r(907),o=r(629),u=r(593),f=r(449),a=r(755);function c(n,t){return function(r,e){const i=t(e[e.length-1]),o=n(i.first(),i.rest());if("function"==typeof o){const n=(n,r)=>(o(t(r[r.length-1])),0);r.push(n)}}}function s(n){return n|=n>>1,n|=n>>2,1+(n|=n>>4)>>1}t.to_pre_eval_op=c,t.msb_mask=s,t.run_program=function(n,t,r,h=e.None,l=e.None){n=i.SExp.to(n);const w=l?c(l,i.SExp.to):e.None;function v(n,t){const r=t.pop(),e=t.pop();return t.push(r),t.push(e),0}function d(n,t){const r=t.pop(),e=t.pop();return t.push(r.cons(e)),0}function y(n,t){w&&w(n,t);const e=t.pop(),c=e.first(),h=e.rest();if(!o.isCons(c)){const[n,r]=function(n,t){let r=f.PATH_LOOKUP_BASE_COST;if(r+=f.PATH_LOOKUP_COST_PER_LEG,n.nullp())return u.t(r,i.SExp.null());const e=n.atom;let c=0;for(;cc||wh)throw new a.EvalError("cost exceeded",i.SExp.to(h));return u.t(g,m[m.length-1])}},351:function(n,t,r){"use strict";Object.defineProperty(t,"un",{value:!0}),t.sexp_buffer_from_stream=t.sexp_from_stream=t.sexp_to_stream=t.atom_to_byte_iterator=t.sexp_to_byte_iterator=void 0;const e=r(593),i=r(959),o=r(629),u=127;function*f(n){const t=[n];for(;t.length;){const r=(n=t.pop()).as_pair();r?(yield new e.Bytes(new Uint8Array([255])),t.push(r[1]),t.push(r[0])):yield*a(n.atom)}}function*a(n){const t=n?n.length:0;if(0===t||!n)return void(yield new e.Bytes(new Uint8Array([128])));if(1===t&&n.get_byte_at(0)<=127)return void(yield n);let r;if(t<64)r=Uint8Array.from([128|t]);else if(t<8192)r=Uint8Array.from([192|t>>8,t>>0&255]);else if(t<1048576)r=Uint8Array.from([224|t>>16,t>>8&255,t>>0&255]);else if(t<134217728)r=Uint8Array.from([240|t>>24,t>>16&255,t>>8&255,t>>0&255]);else{if(!(t<17179869184))throw new Error(`sexp too long ${n}`);r=Uint8Array.from([248|t/2**32>>0,t/2**24>>0&255,t/65536>>0&255,t/256>>0&255,t/1>>0&255])}const i=new e.Bytes(r);yield i,yield n}function c(n,t,r,o){const f=r.read(1);if(0===f.length)throw new Error("bad encoding");const a=f.get_byte_at(0);if(255===a)return n.push(s),n.push(c),void n.push(c);t.push(function(n,t,r){if(128===t)return r(e.Bytes.NULL);if(t<=u)return r(e.Bytes.from([t]));let o=0,f=128;for(;t&f;)o+=1,t&=255^f,f>>=1;let a=e.Bytes.from([t]);if(o>1){const t=n.read(o-1);if(t.length!==o-1)throw new Error("bad encoding");a=a.concat(t)}const c=i.int_from_bytes(a);if(c>=17179869184)throw new Error("blob too large");const s=n.read(c);if(s.length!==c)throw new Error("bad encoding");return r(s)}(r,a,o))}function s(n,t,r,i){const o=t.pop(),u=t.pop();t.push(i(e.t(u,o)))}function h(n){const t=n.read(1);if(0===t.length)throw new Error("bad encoding");const r=t.get_byte_at(0);return 255===r?e.t(t,2):e.t(function(n,t){if(128===t)return e.Bytes.from([t]);if(t<=u)return e.Bytes.from([t]);let r=0,o=128,f=t;for(;f&o;)r+=1,f&=255^o,o>>=1;let a=e.Bytes.from([f]);if(r>1){const t=n.read(r-1);if(t.length!==r-1)throw new Error("bad encoding");a=a.concat(t)}const c=i.int_from_bytes(a);if(c>=17179869184)throw new Error("blob too large");const s=n.read(c);if(s.length!==c)throw new Error("bad encoding");return e.Bytes.from([t]).concat(a.slice(1)).concat(s)}(n,r),0)}t.sexp_to_byte_iterator=f,t.atom_to_byte_iterator=a,t.sexp_to_stream=function(n,t){for(const r of f(n))t.write(r)},t.sexp_from_stream=function(n,t){const r=[c],e=[];for(;r.length;){const t=r.pop();t&&t(r,e,n,(n=>new o.CLVMObject(n)))}return t(e.pop())},t.sexp_buffer_from_stream=function(n){const t=new e.Stream;let r=1;for(;r>0;){r-=1;const[e,i]=h(n);r+=i,t.write(e)}return t.getValue()}},135:function(){},33:function(){},794:function(){},845:function(){}},t={},function r(e){var i=t[e];if(void 0!==i)return i.exports;var o=t[e]={exports:{}};return n[e].call(o.exports,o,o.exports,r),o.exports}(465);var n,t})); \ No newline at end of file diff --git a/.dist/npm/casts.d.ts b/.dist/npm/casts.d.ts deleted file mode 100644 index a53fd65..0000000 --- a/.dist/npm/casts.d.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { int, None } from "./__python_types__"; -import { Bytes } from "./__type_compatibility__"; -export declare function int_from_bytes(b: Bytes | None): int; -export declare function int_to_bytes(v: int): Bytes; -/** - * Return the number of bytes required to represent this integer. - * @param {int} v - */ -export declare function limbs_for_int(v: int): int; diff --git a/.dist/npm/casts.js b/.dist/npm/casts.js deleted file mode 100644 index 6b6e511..0000000 --- a/.dist/npm/casts.js +++ /dev/null @@ -1,47 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.limbs_for_int = exports.int_to_bytes = exports.int_from_bytes = void 0; -const __type_compatibility__1 = require("./__type_compatibility__"); -// In javascript, max safe integer is 2**53-1 (53bit) -// Surprisingly, parseInt() can parse over 32bit integer. -function int_from_bytes(b) { - if (!b || b.length === 0) { - return 0; - } - const unsigned32 = parseInt(b.hex(), 16); - // If the first bit is 1, it is recognized as a negative number. - if (b.get_byte_at(0) & 0x80) { - return unsigned32 - (1 << (b.length * 8)); - } - return unsigned32; -} -exports.int_from_bytes = int_from_bytes; -function int_to_bytes(v) { - if (v > Number.MAX_SAFE_INTEGER || v < Number.MIN_SAFE_INTEGER) { - throw new Error(`The int value is beyond ${v > 0 ? "MAX_SAFE_INTEGER" : "MIN_SAFE_INTEGER"}: ${v}`); - } - if (v === 0) { - return __type_compatibility__1.Bytes.NULL; - } - const byte_count = ((v < 0 ? -v : v).toString(2).length + 8) >> 3; - let hexStr = (v >>> 0).toString(16); - if (v >= 0) { - hexStr = hexStr.length % 2 ? `0${hexStr}` : hexStr; - } - while (hexStr.length / 2 < byte_count) { - hexStr = "00" + hexStr; - } - while (hexStr.length > 2 && hexStr.substr(0, 2) === (parseInt(hexStr.substr(2, 2), 16) & 0x80 ? "ff" : "00")) { - hexStr = hexStr.substr(2); - } - return __type_compatibility__1.h(hexStr); -} -exports.int_to_bytes = int_to_bytes; -/** - * Return the number of bytes required to represent this integer. - * @param {int} v - */ -function limbs_for_int(v) { - return ((v < 0 ? -v : v).toString(2).length + 7) >> 3; -} -exports.limbs_for_int = limbs_for_int; diff --git a/.dist/npm/core_ops.d.ts b/.dist/npm/core_ops.d.ts deleted file mode 100644 index 4cdb6c4..0000000 --- a/.dist/npm/core_ops.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { SExp } from "./SExp"; -export declare function op_if(args: SExp): import("./__type_compatibility__").Tuple; -export declare function op_cons(args: SExp): import("./__type_compatibility__").Tuple; -export declare function op_first(args: SExp): import("./__type_compatibility__").Tuple; -export declare function op_rest(args: SExp): import("./__type_compatibility__").Tuple; -export declare function op_listp(args: SExp): import("./__type_compatibility__").Tuple; -export declare function op_raise(args: SExp): void; -export declare function op_eq(args: SExp): import("./__type_compatibility__").Tuple; diff --git a/.dist/npm/core_ops.js b/.dist/npm/core_ops.js deleted file mode 100644 index f49dee5..0000000 --- a/.dist/npm/core_ops.js +++ /dev/null @@ -1,66 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.op_eq = exports.op_raise = exports.op_listp = exports.op_rest = exports.op_first = exports.op_cons = exports.op_if = void 0; -const SExp_1 = require("./SExp"); -const __type_compatibility__1 = require("./__type_compatibility__"); -const costs_1 = require("./costs"); -const EvalError_1 = require("./EvalError"); -function op_if(args) { - if (args.list_len() !== 3) { - throw new EvalError_1.EvalError("i takes exactly 3 arguments", args); - } - const r = args.rest(); - if (args.first().nullp()) { - return __type_compatibility__1.t(costs_1.IF_COST, r.rest().first()); - } - return __type_compatibility__1.t(costs_1.IF_COST, r.first()); -} -exports.op_if = op_if; -function op_cons(args) { - if (args.list_len() !== 2) { - throw new EvalError_1.EvalError("c takes exactly 2 arguments", args); - } - return __type_compatibility__1.t(costs_1.CONS_COST, args.first().cons(args.rest().first())); -} -exports.op_cons = op_cons; -function op_first(args) { - if (args.list_len() !== 1) { - throw new EvalError_1.EvalError("f takes exactly 1 argument", args); - } - return __type_compatibility__1.t(costs_1.FIRST_COST, args.first().first()); -} -exports.op_first = op_first; -function op_rest(args) { - if (args.list_len() !== 1) { - throw new EvalError_1.EvalError("r takes exactly 1 argument", args); - } - return __type_compatibility__1.t(costs_1.REST_COST, args.first().rest()); -} -exports.op_rest = op_rest; -function op_listp(args) { - if (args.list_len() !== 1) { - throw new EvalError_1.EvalError("l takes exactly 1 argument", args); - } - return __type_compatibility__1.t(costs_1.LISTP_COST, args.first().listp() ? SExp_1.SExp.TRUE : SExp_1.SExp.FALSE); -} -exports.op_listp = op_listp; -function op_raise(args) { - throw new EvalError_1.EvalError("clvm raise", args); -} -exports.op_raise = op_raise; -function op_eq(args) { - if (args.list_len() !== 2) { - throw new EvalError_1.EvalError("= takes exactly 2 arguments", args); - } - const a0 = args.first(); - const a1 = args.rest().first(); - if (a0.pair || a1.pair) { - throw new EvalError_1.EvalError("= on list", a0.pair ? a0 : a1); - } - const b0 = a0.atom; - const b1 = a1.atom; - let cost = costs_1.EQ_BASE_COST; - cost += (b0.length + b1.length) * costs_1.EQ_COST_PER_BYTE; - return __type_compatibility__1.t(cost, b0.equal_to(b1) ? SExp_1.SExp.TRUE : SExp_1.SExp.FALSE); -} -exports.op_eq = op_eq; diff --git a/.dist/npm/costs.d.ts b/.dist/npm/costs.d.ts deleted file mode 100644 index 8d42f63..0000000 --- a/.dist/npm/costs.d.ts +++ /dev/null @@ -1,51 +0,0 @@ -export declare const IF_COST = 33; -export declare const CONS_COST = 50; -export declare const FIRST_COST = 30; -export declare const REST_COST = 30; -export declare const LISTP_COST = 19; -export declare const MALLOC_COST_PER_BYTE = 10; -export declare const ARITH_BASE_COST = 99; -export declare const ARITH_COST_PER_BYTE = 3; -export declare const ARITH_COST_PER_ARG = 320; -export declare const LOG_BASE_COST = 100; -export declare const LOG_COST_PER_BYTE = 3; -export declare const LOG_COST_PER_ARG = 264; -export declare const GRS_BASE_COST = 117; -export declare const GRS_COST_PER_BYTE = 1; -export declare const EQ_BASE_COST = 117; -export declare const EQ_COST_PER_BYTE = 1; -export declare const GR_BASE_COST = 498; -export declare const GR_COST_PER_BYTE = 2; -export declare const DIVMOD_BASE_COST = 1116; -export declare const DIVMOD_COST_PER_BYTE = 6; -export declare const DIV_BASE_COST = 988; -export declare const DIV_COST_PER_BYTE = 4; -export declare const SHA256_BASE_COST = 87; -export declare const SHA256_COST_PER_ARG = 134; -export declare const SHA256_COST_PER_BYTE = 2; -export declare const POINT_ADD_BASE_COST = 101094; -export declare const POINT_ADD_COST_PER_ARG = 1343980; -export declare const PUBKEY_BASE_COST = 1325730; -export declare const PUBKEY_COST_PER_BYTE = 38; -export declare const MUL_BASE_COST = 92; -export declare const MUL_COST_PER_OP = 885; -export declare const MUL_LINEAR_COST_PER_BYTE = 6; -export declare const MUL_SQUARE_COST_PER_BYTE_DIVIDER = 128; -export declare const STRLEN_BASE_COST = 173; -export declare const STRLEN_COST_PER_BYTE = 1; -export declare const PATH_LOOKUP_BASE_COST = 40; -export declare const PATH_LOOKUP_COST_PER_LEG = 4; -export declare const PATH_LOOKUP_COST_PER_ZERO_BYTE = 4; -export declare const CONCAT_BASE_COST = 142; -export declare const CONCAT_COST_PER_ARG = 135; -export declare const CONCAT_COST_PER_BYTE = 3; -export declare const BOOL_BASE_COST = 200; -export declare const BOOL_COST_PER_ARG = 300; -export declare const ASHIFT_BASE_COST = 596; -export declare const ASHIFT_COST_PER_BYTE = 3; -export declare const LSHIFT_BASE_COST = 277; -export declare const LSHIFT_COST_PER_BYTE = 3; -export declare const LOGNOT_BASE_COST = 331; -export declare const LOGNOT_COST_PER_BYTE = 3; -export declare const APPLY_COST = 90; -export declare const QUOTE_COST = 20; diff --git a/.dist/npm/costs.js b/.dist/npm/costs.js deleted file mode 100644 index fa4e040..0000000 --- a/.dist/npm/costs.js +++ /dev/null @@ -1,55 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.APPLY_COST = exports.LOGNOT_COST_PER_BYTE = exports.LOGNOT_BASE_COST = exports.LSHIFT_COST_PER_BYTE = exports.LSHIFT_BASE_COST = exports.ASHIFT_COST_PER_BYTE = exports.ASHIFT_BASE_COST = exports.BOOL_COST_PER_ARG = exports.BOOL_BASE_COST = exports.CONCAT_COST_PER_BYTE = exports.CONCAT_COST_PER_ARG = exports.CONCAT_BASE_COST = exports.PATH_LOOKUP_COST_PER_ZERO_BYTE = exports.PATH_LOOKUP_COST_PER_LEG = exports.PATH_LOOKUP_BASE_COST = exports.STRLEN_COST_PER_BYTE = exports.STRLEN_BASE_COST = exports.MUL_SQUARE_COST_PER_BYTE_DIVIDER = exports.MUL_LINEAR_COST_PER_BYTE = exports.MUL_COST_PER_OP = exports.MUL_BASE_COST = exports.PUBKEY_COST_PER_BYTE = exports.PUBKEY_BASE_COST = exports.POINT_ADD_COST_PER_ARG = exports.POINT_ADD_BASE_COST = exports.SHA256_COST_PER_BYTE = exports.SHA256_COST_PER_ARG = exports.SHA256_BASE_COST = exports.DIV_COST_PER_BYTE = exports.DIV_BASE_COST = exports.DIVMOD_COST_PER_BYTE = exports.DIVMOD_BASE_COST = exports.GR_COST_PER_BYTE = exports.GR_BASE_COST = exports.EQ_COST_PER_BYTE = exports.EQ_BASE_COST = exports.GRS_COST_PER_BYTE = exports.GRS_BASE_COST = exports.LOG_COST_PER_ARG = exports.LOG_COST_PER_BYTE = exports.LOG_BASE_COST = exports.ARITH_COST_PER_ARG = exports.ARITH_COST_PER_BYTE = exports.ARITH_BASE_COST = exports.MALLOC_COST_PER_BYTE = exports.LISTP_COST = exports.REST_COST = exports.FIRST_COST = exports.CONS_COST = exports.IF_COST = void 0; -exports.QUOTE_COST = void 0; -exports.IF_COST = 33; -exports.CONS_COST = 50; -exports.FIRST_COST = 30; -exports.REST_COST = 30; -exports.LISTP_COST = 19; -exports.MALLOC_COST_PER_BYTE = 10; -exports.ARITH_BASE_COST = 99; -exports.ARITH_COST_PER_BYTE = 3; -exports.ARITH_COST_PER_ARG = 320; -exports.LOG_BASE_COST = 100; -exports.LOG_COST_PER_BYTE = 3; -exports.LOG_COST_PER_ARG = 264; -exports.GRS_BASE_COST = 117; -exports.GRS_COST_PER_BYTE = 1; -exports.EQ_BASE_COST = 117; -exports.EQ_COST_PER_BYTE = 1; -exports.GR_BASE_COST = 498; -exports.GR_COST_PER_BYTE = 2; -exports.DIVMOD_BASE_COST = 1116; -exports.DIVMOD_COST_PER_BYTE = 6; -exports.DIV_BASE_COST = 988; -exports.DIV_COST_PER_BYTE = 4; -exports.SHA256_BASE_COST = 87; -exports.SHA256_COST_PER_ARG = 134; -exports.SHA256_COST_PER_BYTE = 2; -exports.POINT_ADD_BASE_COST = 101094; -exports.POINT_ADD_COST_PER_ARG = 1343980; -exports.PUBKEY_BASE_COST = 1325730; -exports.PUBKEY_COST_PER_BYTE = 38; -exports.MUL_BASE_COST = 92; -exports.MUL_COST_PER_OP = 885; -exports.MUL_LINEAR_COST_PER_BYTE = 6; -exports.MUL_SQUARE_COST_PER_BYTE_DIVIDER = 128; -exports.STRLEN_BASE_COST = 173; -exports.STRLEN_COST_PER_BYTE = 1; -exports.PATH_LOOKUP_BASE_COST = 40; -exports.PATH_LOOKUP_COST_PER_LEG = 4; -exports.PATH_LOOKUP_COST_PER_ZERO_BYTE = 4; -exports.CONCAT_BASE_COST = 142; -exports.CONCAT_COST_PER_ARG = 135; -exports.CONCAT_COST_PER_BYTE = 3; -exports.BOOL_BASE_COST = 200; -exports.BOOL_COST_PER_ARG = 300; -exports.ASHIFT_BASE_COST = 596; -exports.ASHIFT_COST_PER_BYTE = 3; -exports.LSHIFT_BASE_COST = 277; -exports.LSHIFT_COST_PER_BYTE = 3; -exports.LOGNOT_BASE_COST = 331; -exports.LOGNOT_COST_PER_BYTE = 3; -exports.APPLY_COST = 90; -exports.QUOTE_COST = 20; diff --git a/.dist/npm/index.d.ts b/.dist/npm/index.d.ts deleted file mode 100644 index b2977f8..0000000 --- a/.dist/npm/index.d.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { SExp } from "./SExp"; -export * from "./__debug__"; -export * from "./__bls_signatures__"; -export * from "./__python_types__"; -export * from "./__type_compatibility__"; -export * from "./as_javascript"; -export * from "./casts"; -export * from "./CLVMObject"; -export * from "./core_ops"; -export * from "./costs"; -export * from "./EvalError"; -export * from "./initialize"; -export * from "./more_ops"; -export * from "./op_utils"; -export * from "./operators"; -export * from "./run_program"; -export * from "./serialize"; -export * from "./SExp"; -export declare const to_sexp_f: typeof SExp.to; diff --git a/.dist/npm/index.js b/.dist/npm/index.js deleted file mode 100644 index 8f37299..0000000 --- a/.dist/npm/index.js +++ /dev/null @@ -1,32 +0,0 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __exportStar = (this && this.__exportStar) || function(m, exports) { - for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.to_sexp_f = void 0; -const SExp_1 = require("./SExp"); -__exportStar(require("./__debug__"), exports); -__exportStar(require("./__bls_signatures__"), exports); -__exportStar(require("./__python_types__"), exports); -__exportStar(require("./__type_compatibility__"), exports); -__exportStar(require("./as_javascript"), exports); -__exportStar(require("./casts"), exports); -__exportStar(require("./CLVMObject"), exports); -__exportStar(require("./core_ops"), exports); -__exportStar(require("./costs"), exports); -__exportStar(require("./EvalError"), exports); -__exportStar(require("./initialize"), exports); -__exportStar(require("./more_ops"), exports); -__exportStar(require("./op_utils"), exports); -__exportStar(require("./operators"), exports); -__exportStar(require("./run_program"), exports); -__exportStar(require("./serialize"), exports); -__exportStar(require("./SExp"), exports); -exports.to_sexp_f = SExp_1.SExp.to; diff --git a/.dist/npm/initialize.d.ts b/.dist/npm/initialize.d.ts deleted file mode 100644 index bef382a..0000000 --- a/.dist/npm/initialize.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Always call and wait this async function to be finished to initialize async bls module loading. - */ -export declare function initialize(): Promise; diff --git a/.dist/npm/initialize.js b/.dist/npm/initialize.js deleted file mode 100644 index d748737..0000000 --- a/.dist/npm/initialize.js +++ /dev/null @@ -1,22 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.initialize = void 0; -const __bls_signatures__1 = require("./__bls_signatures__"); -/** - * Always call and wait this async function to be finished to initialize async bls module loading. - */ -function initialize() { - return __awaiter(this, void 0, void 0, function* () { - yield __bls_signatures__1.initializeBLS(); - }); -} -exports.initialize = initialize; diff --git a/.dist/npm/more_ops.d.ts b/.dist/npm/more_ops.d.ts deleted file mode 100644 index 8cf30f8..0000000 --- a/.dist/npm/more_ops.d.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { SExp } from "./SExp"; -import { Tuple } from "./__type_compatibility__"; -import { int, str } from "./__python_types__"; -export declare function malloc_cost(cost: int, atom: SExp): Tuple; -export declare function op_sha256(args: SExp): Tuple; -export declare function args_as_ints(op_name: str, args: SExp): Generator, void, unknown>; -export declare function args_as_int32(op_name: str, args: SExp): Generator; -export declare function args_as_int_list(op_name: str, args: SExp, count: int): Tuple[]; -export declare function args_as_bools(op_name: str, args: SExp): Generator; -export declare function args_as_bool_list(op_name: str, args: SExp, count: int): SExp[]; -export declare function op_add(args: SExp): Tuple; -export declare function op_subtract(args: SExp): Tuple; -export declare function op_multiply(args: SExp): Tuple; -export declare function op_divmod(args: SExp): Tuple; -export declare function op_div(args: SExp): Tuple; -export declare function op_gr(args: SExp): Tuple; -export declare function op_gr_bytes(args: SExp): Tuple; -export declare function op_pubkey_for_exp(items: SExp): Tuple; -export declare function op_strlen(args: SExp): Tuple; -export declare function op_substr(args: SExp): Tuple; -export declare function op_concat(args: SExp): Tuple; -export declare function op_ash(args: SExp): Tuple; -export declare function op_lsh(args: SExp): Tuple; -export declare function binop_reduction(op_name: str, initial_value: number, args: SExp, op_f: Function): Tuple; -export declare function op_logand(args: SExp): Tuple; -export declare function op_logior(args: SExp): Tuple; -export declare function op_logxor(args: SExp): Tuple; -export declare function op_lognot(args: SExp): Tuple; -export declare function op_not(args: SExp): Tuple; -export declare function op_any(args: SExp): Tuple; -export declare function op_all(args: SExp): Tuple; -export declare function op_softfork(args: SExp): Tuple; diff --git a/.dist/npm/more_ops.js b/.dist/npm/more_ops.js deleted file mode 100644 index ed80d08..0000000 --- a/.dist/npm/more_ops.js +++ /dev/null @@ -1,438 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.op_softfork = exports.op_all = exports.op_any = exports.op_not = exports.op_lognot = exports.op_logxor = exports.op_logior = exports.op_logand = exports.binop_reduction = exports.op_lsh = exports.op_ash = exports.op_concat = exports.op_substr = exports.op_strlen = exports.op_pubkey_for_exp = exports.op_gr_bytes = exports.op_gr = exports.op_div = exports.op_divmod = exports.op_multiply = exports.op_subtract = exports.op_add = exports.args_as_bool_list = exports.args_as_bools = exports.args_as_int_list = exports.args_as_int32 = exports.args_as_ints = exports.op_sha256 = exports.malloc_cost = void 0; -const SHA256_1 = require("jscrypto/SHA256"); -const SExp_1 = require("./SExp"); -const costs_1 = require("./costs"); -const __type_compatibility__1 = require("./__type_compatibility__"); -const EvalError_1 = require("./EvalError"); -const casts_1 = require("./casts"); -const CLVMObject_1 = require("./CLVMObject"); -const __bls_signatures__1 = require("./__bls_signatures__"); -function malloc_cost(cost, atom) { - if (!atom.atom) { - throw new EvalError_1.EvalError("atom is None", atom); - } - return __type_compatibility__1.t(cost + atom.atom.length * costs_1.MALLOC_COST_PER_BYTE, atom); -} -exports.malloc_cost = malloc_cost; -function op_sha256(args) { - let cost = costs_1.SHA256_BASE_COST; - let arg_len = 0; - const h = new SHA256_1.SHA256(); - for (const _ of args.as_iter()) { - const atom = _.atom; - if (!atom) { - throw new EvalError_1.EvalError("sha256 on list", _); - } - arg_len += atom.length; - cost += costs_1.SHA256_COST_PER_ARG; - h.update(atom.as_word()); - } - cost += arg_len * costs_1.SHA256_COST_PER_BYTE; - return malloc_cost(cost, SExp_1.SExp.to(__type_compatibility__1.Bytes.from(h.finalize().toUint8Array()))); -} -exports.op_sha256 = op_sha256; -function* args_as_ints(op_name, args) { - for (const arg of args.as_iter()) { - if (arg.pair || !arg.atom) { - throw new EvalError_1.EvalError(`${op_name} requires int args`, arg); - } - yield __type_compatibility__1.t(arg.as_int(), arg.atom.length); - } -} -exports.args_as_ints = args_as_ints; -function* args_as_int32(op_name, args) { - for (const arg of args.as_iter()) { - if (arg.pair || !arg.atom) { - throw new EvalError_1.EvalError(`${op_name} requires int32 args`, arg); - } - else if (arg.atom.length > 4) { - throw new EvalError_1.EvalError(`${op_name} requires int32 args (with no leading zeros`, arg); - } - yield arg.as_int(); - } -} -exports.args_as_int32 = args_as_int32; -function args_as_int_list(op_name, args, count) { - const int_list = []; - for (const _ of args_as_ints(op_name, args)) - int_list.push(_); - if (int_list.length !== count) { - const plural = count !== 1 ? "s" : ""; - throw new EvalError_1.EvalError(`${op_name} takes exactly ${count} argument${plural}`, args); - } - return int_list; -} -exports.args_as_int_list = args_as_int_list; -function* args_as_bools(op_name, args) { - for (const arg of args.as_iter()) { - const v = arg.atom; - if (v === null || v === void 0 ? void 0 : v.equal_to(__type_compatibility__1.Bytes.NULL)) { - yield SExp_1.SExp.FALSE; - } - else { - yield SExp_1.SExp.TRUE; - } - } -} -exports.args_as_bools = args_as_bools; -function args_as_bool_list(op_name, args, count) { - const bool_list = []; - for (const _ of args_as_bools(op_name, args)) - bool_list.push(_); - if (bool_list.length !== count) { - const plural = count !== 1 ? "s" : ""; - throw new EvalError_1.EvalError(`${op_name} takes exactly ${count} argument${plural}`, args); - } - return bool_list; -} -exports.args_as_bool_list = args_as_bool_list; -function op_add(args) { - let total = 0; - let cost = costs_1.ARITH_BASE_COST; - let arg_size = 0; - for (const ints of args_as_ints("+", args)) { - const [r, l] = ints; - total += r; - arg_size += l; - cost += costs_1.ARITH_COST_PER_ARG; - } - cost += arg_size * costs_1.ARITH_COST_PER_BYTE; - return malloc_cost(cost, SExp_1.SExp.to(total)); -} -exports.op_add = op_add; -function op_subtract(args) { - let cost = costs_1.ARITH_BASE_COST; - if (args.nullp()) { - return malloc_cost(cost, SExp_1.SExp.to(0)); - } - let sign = 1; - let total = 0; - let arg_size = 0; - for (const ints of args_as_ints("-", args)) { - const [r, l] = ints; - total += sign * r; - sign = -1; - arg_size += l; - cost += costs_1.ARITH_COST_PER_BYTE; - } - cost += arg_size * costs_1.ARITH_COST_PER_BYTE; - return malloc_cost(cost, SExp_1.SExp.to(total)); -} -exports.op_subtract = op_subtract; -function op_multiply(args) { - let cost = costs_1.MUL_BASE_COST; - const operands = args_as_ints("*", args); - const res = operands.next(); - if (res.done) { - return malloc_cost(cost, SExp_1.SExp.to(1)); - } - let [v, vs] = res.value; - for (const o of operands) { - const [r, rs] = o; - cost += costs_1.MUL_COST_PER_OP; - cost += (rs + vs) * costs_1.MUL_LINEAR_COST_PER_BYTE; - cost += ((rs * vs) / costs_1.MUL_SQUARE_COST_PER_BYTE_DIVIDER) >> 0; - v = v * r; - vs = casts_1.limbs_for_int(v); - } - return malloc_cost(cost, SExp_1.SExp.to(v)); -} -exports.op_multiply = op_multiply; -function op_divmod(args) { - let cost = costs_1.DIVMOD_BASE_COST; - const [t1, t2] = args_as_int_list("divmod", args, 2); - const [i0, l0] = t1; - const [i1, l1] = t2; - if (i1 === 0) { - throw new EvalError_1.EvalError("divmod with 0", SExp_1.SExp.to(i0)); - } - cost += (l0 + l1) * costs_1.DIVMOD_COST_PER_BYTE; - const q = (i0 / i1) >> 0; - const r = i0 % i1; - const q1 = SExp_1.SExp.to(q); - const r1 = SExp_1.SExp.to(r); - cost += (q1.atom.length + r1.atom.length) * costs_1.MALLOC_COST_PER_BYTE; - return __type_compatibility__1.t(cost, SExp_1.SExp.to(__type_compatibility__1.t(q, r))); -} -exports.op_divmod = op_divmod; -function op_div(args) { - let cost = costs_1.DIV_BASE_COST; - const [t1, t2] = args_as_int_list("/", args, 2); - const [i0, l0] = t1; - const [i1, l1] = t2; - if (i1 === 0) { - throw new EvalError_1.EvalError("div with 0", SExp_1.SExp.to(i0)); - } - cost += (l0 + l1) * costs_1.DIV_COST_PER_BYTE; - const q = (i0 / i1) >> 0; - return malloc_cost(cost, SExp_1.SExp.to(q)); -} -exports.op_div = op_div; -function op_gr(args) { - const [t1, t2] = args_as_int_list(">", args, 2); - const [i0, l0] = t1; - const [i1, l1] = t2; - let cost = costs_1.GR_BASE_COST; - cost += (l0 + l1) * costs_1.GR_COST_PER_BYTE; - return __type_compatibility__1.t(cost, i0 > i1 ? SExp_1.SExp.TRUE : SExp_1.SExp.FALSE); -} -exports.op_gr = op_gr; -function op_gr_bytes(args) { - const arg_list = []; - for (const _ of args.as_iter()) - arg_list.push(_); - if (arg_list.length !== 2) { - throw new EvalError_1.EvalError(">s takes exactly 2 arguments", args); - } - const [a0, a1] = arg_list; - if (a0.pair || a1.pair) { - throw new EvalError_1.EvalError(">s on list", a0.pair ? a0 : a1); - } - const b0 = a0.atom; - const b1 = a1.atom; - let cost = costs_1.GRS_BASE_COST; - cost += (b0.length + b1.length) * costs_1.GRS_COST_PER_BYTE; - return __type_compatibility__1.t(cost, b0.compare(b1) > 0 /* b0 > b1 */ ? SExp_1.SExp.TRUE : SExp_1.SExp.FALSE); -} -exports.op_gr_bytes = op_gr_bytes; -function op_pubkey_for_exp(items) { - let cost = costs_1.POINT_ADD_BASE_COST; - const { G1Element } = __bls_signatures__1.getBLSModule(); - let p = new G1Element(); - for (const _ of items.as_iter()) { - if (!CLVMObject_1.isAtom(_)) { - throw new EvalError_1.EvalError("point_add on list", _); - } - try { - const atom_g1 = __bls_signatures__1.G1Element_from_bytes(_.atom.data()); - p = __bls_signatures__1.G1Element_add(p, atom_g1); - cost += costs_1.POINT_ADD_COST_PER_ARG; - } - catch (e) { - throw new EvalError_1.EvalError(`point_add expects blob, got ${_.atom}: ${JSON.stringify(e)}`, items); - } - } - return malloc_cost(cost, SExp_1.SExp.to(p)); -} -exports.op_pubkey_for_exp = op_pubkey_for_exp; -function op_strlen(args) { - if (args.list_len() !== 1) { - throw new EvalError_1.EvalError("strlen takes exactly 1 argument", args); - } - const a0 = args.first(); - if (!CLVMObject_1.isAtom(a0)) { - throw new EvalError_1.EvalError("strlen on list", a0); - } - const size = a0.atom.length; - const cost = costs_1.STRLEN_BASE_COST + size * costs_1.STRLEN_COST_PER_BYTE; - return malloc_cost(cost, SExp_1.SExp.to(size)); -} -exports.op_strlen = op_strlen; -function op_substr(args) { - const arg_count = args.list_len(); - if (![2, 3].includes(arg_count)) { - throw new EvalError_1.EvalError("substr takes exactly 2 or 3 arguments", args); - } - const a0 = args.first(); - if (!CLVMObject_1.isAtom(a0)) { - throw new EvalError_1.EvalError("substr on list", a0); - } - const s0 = a0.atom; - let i1; - let i2; - if (arg_count === 2) { - i1 = args_as_int32("substr", args.rest()).next().value; - i2 = s0.length; - } - else { - const ints = []; - for (const i of args_as_int32("substr", args.rest())) { - ints.push(i); - } - ([i1, i2] = ints); - } - if (i2 > s0.length || i2 < i1 || i2 < 0 || i1 < 0) { - throw new EvalError_1.EvalError("invalid indices for substr", args); - } - const s = s0.slice(i1, i2); - const cost = 1; - return __type_compatibility__1.t(cost, SExp_1.SExp.to(s)); -} -exports.op_substr = op_substr; -function op_concat(args) { - let cost = costs_1.CONCAT_BASE_COST; - const s = new __type_compatibility__1.Stream(); - for (const arg of args.as_iter()) { - if (!CLVMObject_1.isAtom(arg)) { - throw new EvalError_1.EvalError("concat on list", arg); - } - s.write(arg.atom); - cost += costs_1.CONCAT_COST_PER_ARG; - } - const r = s.getValue(); - cost += r.length * costs_1.CONCAT_COST_PER_BYTE; - return malloc_cost(cost, SExp_1.SExp.to(r)); -} -exports.op_concat = op_concat; -function op_ash(args) { - const [t1, t2] = args_as_int_list("ash", args, 2); - const [i0, l0] = t1; - const [i1, l1] = t2; - if (l1 > 4) { - throw new EvalError_1.EvalError("ash requires int32 args (with no leading zeros)", args.rest().first()); - } - else if (Math.abs(i1) > 65535) { - throw new EvalError_1.EvalError("shift too large", SExp_1.SExp.to(i1)); - } - let r; - if (i1 >= 0) { - r = i0 << i1; - } - else { - r = i0 >> -i1; - } - let cost = costs_1.ASHIFT_BASE_COST; - cost += (l0 + casts_1.limbs_for_int(r)) * costs_1.ASHIFT_COST_PER_BYTE; - return malloc_cost(cost, SExp_1.SExp.to(r)); -} -exports.op_ash = op_ash; -function op_lsh(args) { - const [t1, t2] = args_as_int_list("lsh", args, 2); - const l0 = t1[1]; - const [i1, l1] = t2; - if (l1 > 4) { - throw new EvalError_1.EvalError("lsh requires int32 args (with no leading zeros)", args.rest().first()); - } - else if (Math.abs(i1) > 65535) { - throw new EvalError_1.EvalError("shift too large", SExp_1.SExp.to(i1)); - } - // we actually want i0 to be an *unsigned* int - const a0 = args.first().atom; - const i0 = casts_1.int_from_bytes(a0); - let r; - if (i1 >= 0) { - r = i0 << i1; - } - else { - r = i0 >> -i1; - } - let cost = costs_1.LSHIFT_BASE_COST; - cost += (l0 + casts_1.limbs_for_int(r)) * costs_1.LSHIFT_COST_PER_BYTE; - return malloc_cost(cost, SExp_1.SExp.to(r)); -} -exports.op_lsh = op_lsh; -// eslint-disable-next-line @typescript-eslint/ban-types -function binop_reduction(op_name, initial_value, args, op_f) { - let total = initial_value; - let arg_size = 0; - let cost = costs_1.LOG_BASE_COST; - for (const t of args_as_ints(op_name, args)) { - const [r, l] = t; - total = op_f(total, r); - arg_size += l; - cost += costs_1.LOG_COST_PER_ARG; - } - cost += arg_size * costs_1.LOG_COST_PER_BYTE; - return malloc_cost(cost, SExp_1.SExp.to(total)); -} -exports.binop_reduction = binop_reduction; -function op_logand(args) { - const binop = (a, b) => { - a &= b; - return a; - }; - return binop_reduction("logand", -1, args, binop); -} -exports.op_logand = op_logand; -function op_logior(args) { - const binop = (a, b) => { - a |= b; - return a; - }; - return binop_reduction("logior", 0, args, binop); -} -exports.op_logior = op_logior; -function op_logxor(args) { - const binop = (a, b) => { - a ^= b; - return a; - }; - return binop_reduction("logxor", 0, args, binop); -} -exports.op_logxor = op_logxor; -function op_lognot(args) { - const t = args_as_int_list("lognot", args, 1); - const [i0, l0] = t[0]; - const cost = costs_1.LOGNOT_BASE_COST + l0 * costs_1.LOGNOT_COST_PER_BYTE; - return malloc_cost(cost, SExp_1.SExp.to(~i0)); -} -exports.op_lognot = op_lognot; -function op_not(args) { - const boolList = args_as_bool_list("not", args, 1); - const i0 = boolList[0]; - if (!CLVMObject_1.isAtom(i0)) { - throw new EvalError_1.EvalError("not on list", args); - } - let r; - if (i0.atom.equal_to(__type_compatibility__1.Bytes.NULL)) { - r = SExp_1.SExp.TRUE; - } - else { - r = SExp_1.SExp.FALSE; - } - return __type_compatibility__1.t(costs_1.BOOL_BASE_COST, SExp_1.SExp.to(r)); -} -exports.op_not = op_not; -function op_any(args) { - const items = []; - for (const _ of args_as_bools("any", args)) - items.push(_); - const cost = costs_1.BOOL_BASE_COST + items.length * costs_1.BOOL_COST_PER_ARG; - let r = SExp_1.SExp.FALSE; - for (const v of items) { - if (!CLVMObject_1.isAtom(v)) { - throw new EvalError_1.EvalError("any on list", args); - } - if (!v.atom.equal_to(__type_compatibility__1.Bytes.NULL)) { - r = SExp_1.SExp.TRUE; - break; - } - } - return __type_compatibility__1.t(cost, SExp_1.SExp.to(r)); -} -exports.op_any = op_any; -function op_all(args) { - const items = []; - for (const _ of args_as_bools("all", args)) - items.push(_); - const cost = costs_1.BOOL_BASE_COST + items.length * costs_1.BOOL_COST_PER_ARG; - let r = SExp_1.SExp.TRUE; - for (const v of items) { - if (!CLVMObject_1.isAtom(v)) { - throw new EvalError_1.EvalError("all on list", args); - } - if (v.atom.equal_to(__type_compatibility__1.Bytes.NULL)) { - r = SExp_1.SExp.FALSE; - break; - } - } - return __type_compatibility__1.t(cost, SExp_1.SExp.to(r)); -} -exports.op_all = op_all; -function op_softfork(args) { - if (args.list_len() < 1) { - throw new EvalError_1.EvalError("softfork takes at least 1 argument", args); - } - const a = args.first(); - if (!CLVMObject_1.isAtom(a)) { - throw new EvalError_1.EvalError("softfork requires int args", a); - } - const cost = a.as_int(); - if (cost < 1) { - throw new EvalError_1.EvalError("cost must be > 0", args); - } - return __type_compatibility__1.t(cost, SExp_1.SExp.FALSE); -} -exports.op_softfork = op_softfork; diff --git a/.dist/npm/op_utils.d.ts b/.dist/npm/op_utils.d.ts deleted file mode 100644 index d7a927c..0000000 --- a/.dist/npm/op_utils.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { str } from "./__python_types__"; -import { SExp } from "./SExp"; -export declare function operators_for_dict(keyword_to_atom: Record, op_dict: Record, op_name_lookup: Record): Record unknown>; -export declare function operators_for_module(keyword_to_atom: Record, mod: Record, op_name_lookup?: Record): Record unknown>; diff --git a/.dist/npm/op_utils.js b/.dist/npm/op_utils.js deleted file mode 100644 index c415e8f..0000000 --- a/.dist/npm/op_utils.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.operators_for_module = exports.operators_for_dict = void 0; -function operators_for_dict(keyword_to_atom, op_dict, op_name_lookup) { - const d = {}; - for (const op of Object.keys(keyword_to_atom)) { - const op_name = `op_${op_name_lookup[op] || op}`; - const op_f = op_dict[op_name]; - if (typeof op_f === "function") { - d[keyword_to_atom[op]] = op_f; - } - } - return d; -} -exports.operators_for_dict = operators_for_dict; -function operators_for_module(keyword_to_atom, mod, op_name_lookup = {}) { - return operators_for_dict(keyword_to_atom, mod, op_name_lookup); -} -exports.operators_for_module = operators_for_module; diff --git a/.dist/npm/operators.d.ts b/.dist/npm/operators.d.ts deleted file mode 100644 index c8ada8c..0000000 --- a/.dist/npm/operators.d.ts +++ /dev/null @@ -1,113 +0,0 @@ -import { int, str } from "./__python_types__"; -import { SExp } from "./SExp"; -import { Bytes, Tuple } from "./__type_compatibility__"; -import { CLVMObject } from "./CLVMObject"; -export declare const KEYWORD_FROM_ATOM: { - "00": string; - "01": string; - "02": string; - "03": string; - "04": string; - "05": string; - "06": string; - "07": string; - "08": string; - "09": string; - "0a": string; - "0b": string; - "0c": string; - "0d": string; - "0e": string; - "0f": string; - "10": string; - "11": string; - "12": string; - "13": string; - "14": string; - "15": string; - "16": string; - "17": string; - "18": string; - "19": string; - "1a": string; - "1b": string; - "1c": string; - "1d": string; - "1e": string; - "1f": string; - "20": string; - "21": string; - "22": string; - "23": string; - "24": string; -}; -export declare const KEYWORD_TO_ATOM: { - q: string; - a: string; - i: string; - c: string; - f: string; - r: string; - l: string; - x: string; - "=": string; - ">s": string; - sha256: string; - substr: string; - strlen: string; - concat: string; - "+": string; - "-": string; - "*": string; - "/": string; - divmod: string; - ">": string; - ash: string; - lsh: string; - logand: string; - logior: string; - logxor: string; - lognot: string; - point_add: string; - pubkey_for_exp: string; - not: string; - any: string; - all: string; - ".": string; - softfork: string; -}; -export declare const OP_REWRITE: { - "+": string; - "-": string; - "*": string; - "/": string; - i: string; - c: string; - f: string; - r: string; - l: string; - x: string; - "=": string; - ">": string; - ">s": string; -}; -export declare type ATOMS = keyof typeof KEYWORD_FROM_ATOM; -export declare type KEYWORDS = keyof typeof KEYWORD_TO_ATOM; -export declare function args_len(op_name: str, args: SExp): Generator; -export declare function default_unknown_op(op: Bytes, args: SExp): Tuple; -export declare const QUOTE_ATOM: Bytes; -export declare const APPLY_ATOM: Bytes; -declare type TOpFunc = (args: SExp) => R; -declare type TBasicAtom = "quote_atom" | "apply_atom"; -declare type TAtomOpFunctionMap = Record & Partial>; -export declare type TOperatorDict = { - unknown_op_handler: typeof default_unknown_op; -} & ((op: Bytes | string | number, args: SExp) => Tuple) & TAtomOpFunctionMap & Record; -export declare type TOperatorDictOption = { - quote_atom: Bytes; - apply_atom: Bytes; - unknown_op_handler: typeof default_unknown_op; -}; -export declare function OperatorDict(atom_op_function_map: TAtomOpFunctionMap | TOperatorDict, option?: Partial): TOperatorDict; -export declare const OPERATOR_LOOKUP: TOperatorDict<"00" | "01" | "02" | "03" | "04" | "05" | "06" | "07" | "08" | "09" | "0a" | "0b" | "0c" | "0d" | "0e" | "10" | "11" | "12" | "13" | "14" | "15" | "16" | "17" | "18" | "19" | "1a" | "1b" | "1d" | "1e" | "20" | "21" | "22" | "23" | "24" | "0f" | "1c" | "1f">; -export {}; diff --git a/.dist/npm/operators.js b/.dist/npm/operators.js deleted file mode 100644 index 3f1189a..0000000 --- a/.dist/npm/operators.js +++ /dev/null @@ -1,309 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.OPERATOR_LOOKUP = exports.OperatorDict = exports.APPLY_ATOM = exports.QUOTE_ATOM = exports.default_unknown_op = exports.args_len = exports.OP_REWRITE = exports.KEYWORD_TO_ATOM = exports.KEYWORD_FROM_ATOM = void 0; -const casts_1 = require("./casts"); -const SExp_1 = require("./SExp"); -const __type_compatibility__1 = require("./__type_compatibility__"); -const EvalError_1 = require("./EvalError"); -const costs_1 = require("./costs"); -const op_utils_1 = require("./op_utils"); -const core_ops = require("./core_ops"); -const more_ops = require("./more_ops"); -/* -export const KEYWORDS = [ - // core opcodes 0x01-x08 - ". q a i c f r l x ", - - // opcodes on atoms as strings 0x09-0x0f - "= >s sha256 substr strlen concat . ", - - // opcodes on atoms as ints 0x10-0x17 - "+ - * / divmod > ash lsh ", - - // opcodes on atoms as vectors of bools 0x18-0x1c - "logand logior logxor lognot . ", - - // opcodes for bls 1381 0x1d-0x1f - "point_add pubkey_for_exp . ", - - // bool opcodes 0x20-0x23 - "not any all . ", - - // misc 0x24 - "softfork ", -].join("").trim().split(/\s/); -export const KEYWORD_FROM_ATOM = Object - .entries(KEYWORDS) - .reduce>((acc, v) => { - acc[int_to_bytes(+v[0]).toString()] = v[1]; - return acc; - }, {}); -export const KEYWORD_TO_ATOM = Object - .entries(KEYWORD_FROM_ATOM) - .reduce>((acc, v) => { - acc[v[1]] = v[0]; - return acc; - }, {}); - */ -exports.KEYWORD_FROM_ATOM = { - "00": ".", - // core opcodes 0x01-x08 - "01": "q", - "02": "a", - "03": "i", - "04": "c", - "05": "f", - "06": "r", - "07": "l", - "08": "x", - // opcodes on atoms as strings 0x09-0x0f - "09": "=", - "0a": ">s", - "0b": "sha256", - "0c": "substr", - "0d": "strlen", - "0e": "concat", - "0f": ".", - // opcodes on atoms as ints 0x10-0x17 - "10": "+", - "11": "-", - "12": "*", - "13": "/", - "14": "divmod", - "15": ">", - "16": "ash", - "17": "lsh", - // opcodes on atoms as vectors of bools 0x18-0x1c - "18": "logand", - "19": "logior", - "1a": "logxor", - "1b": "lognot", - "1c": ".", - // opcodes for bls 1381 0x1d-0x1f - "1d": "point_add", - "1e": "pubkey_for_exp", - "1f": ".", - // bool opcodes 0x20-0x23 - "20": "not", - "21": "any", - "22": "all", - "23": ".", - // misc 0x24 - "24": "softfork", -}; -exports.KEYWORD_TO_ATOM = { - // ".": "00", - // core opcodes 0x01-x08 - "q": "01", - "a": "02", - "i": "03", - "c": "04", - "f": "05", - "r": "06", - "l": "07", - "x": "08", - // opcodes on atoms as strings 0x09-0x0f - "=": "09", - ">s": "0a", - "sha256": "0b", - "substr": "0c", - "strlen": "0d", - "concat": "0e", - // ".": "0f", - // opcodes on atoms as ints 0x10-0x17 - "+": "10", - "-": "11", - "*": "12", - "/": "13", - "divmod": "14", - ">": "15", - "ash": "16", - "lsh": "17", - // opcodes on atoms as vectors of bools 0x18-0x1c - "logand": "18", - "logior": "19", - "logxor": "1a", - "lognot": "1b", - // ".": "1c", - // opcodes for bls 1381 0x1d-0x1f - "point_add": "1d", - "pubkey_for_exp": "1e", - // ".": "1f", - // bool opcodes 0x20-0x23 - "not": "20", - "any": "21", - "all": "22", - ".": "23", - // misc 0x24 - "softfork": "24", -}; -exports.OP_REWRITE = { - "+": "add", - "-": "subtract", - "*": "multiply", - "/": "div", - "i": "if", - "c": "cons", - "f": "first", - "r": "rest", - "l": "listp", - "x": "raise", - "=": "eq", - ">": "gr", - ">s": "gr_bytes", -}; -function* args_len(op_name, args) { - for (const arg of args.as_iter()) { - if (arg.pair) { - throw new EvalError_1.EvalError(`${op_name} requires int args"`, arg); - } - yield arg.atom.length; - } -} -exports.args_len = args_len; -/* -# unknown ops are reserved if they start with 0xffff -# otherwise, unknown ops are no-ops, but they have costs. The cost is computed -# like this: - -# byte index (reverse): -# | 4 | 3 | 2 | 1 | 0 | -# +---+---+---+---+------------+ -# | multiplier |XX | XXXXXX | -# +---+---+---+---+---+--------+ -# ^ ^ ^ -# | | + 6 bits ignored when computing cost -# cost_multiplier | -# + 2 bits -# cost_function - -# 1 is always added to the multiplier before using it to multiply the cost, this -# is since cost may not be 0. - -# cost_function is 2 bits and defines how cost is computed based on arguments: -# 0: constant, cost is 1 * (multiplier + 1) -# 1: computed like operator add, multiplied by (multiplier + 1) -# 2: computed like operator mul, multiplied by (multiplier + 1) -# 3: computed like operator concat, multiplied by (multiplier + 1) - -# this means that unknown ops where cost_function is 1, 2, or 3, may still be -# fatal errors if the arguments passed are not atoms. - */ -function default_unknown_op(op, args) { - // # any opcode starting with ffff is reserved (i.e. fatal error) - // # opcodes are not allowed to be empty - if (op.length === 0 || op.slice(0, 2).equal_to(__type_compatibility__1.Bytes.from("0xffff", "hex"))) { - throw new EvalError_1.EvalError("reserved operator", SExp_1.SExp.to(op)); - } - /* - # all other unknown opcodes are no-ops - # the cost of the no-ops is determined by the opcode number, except the - # 6 least significant bits. - */ - const cost_function = (op.get_byte_at(op.length - 1) & 0b11000000) >> 6; - // # the multiplier cannot be 0. it starts at 1 - if (op.length > 5) { - throw new EvalError_1.EvalError("invalid operator", SExp_1.SExp.to(op)); - } - const cost_multiplier = casts_1.int_from_bytes(op.slice(0, op.length - 1)) + 1; - /* - # 0 = constant - # 1 = like op_add/op_sub - # 2 = like op_multiply - # 3 = like op_concat - */ - let cost; - if (cost_function === 0) { - cost = 1; - } - else if (cost_function === 1) { - cost = costs_1.ARITH_BASE_COST; - let arg_size = 0; - for (const length of args_len("unknown op", args)) { - arg_size += length; - cost += costs_1.ARITH_COST_PER_ARG; - } - cost += arg_size * costs_1.ARITH_COST_PER_BYTE; - } - else if (cost_function === 2) { - // # like op_multiply - cost = costs_1.MUL_BASE_COST; - const operands = args_len("unknown op", args); - const res = operands.next(); - if (!res.done) { - let vs = res.value; - for (const rs of operands) { - cost += costs_1.MUL_COST_PER_OP; - cost += (rs + vs) * costs_1.MUL_LINEAR_COST_PER_BYTE; - cost += ((rs * vs) / costs_1.MUL_SQUARE_COST_PER_BYTE_DIVIDER) >> 0; - vs += rs; - } - } - } - else if (cost_function === 3) { - // # like concat - cost = costs_1.CONCAT_BASE_COST; - let length = 0; - for (const arg of args.as_iter()) { - if (arg.pair) { - throw new EvalError_1.EvalError("unknown op on list", arg); - } - cost += costs_1.CONCAT_COST_PER_ARG; - length += arg.atom.length; - } - cost += length * costs_1.CONCAT_COST_PER_BYTE; - } - else { - throw new Error(`Invalid cost_function: ${cost_function}`); - } - cost *= cost_multiplier; - if (cost >= 2 ** 32) { - throw new EvalError_1.EvalError("invalid operator", SExp_1.SExp.to(op)); - } - return __type_compatibility__1.t(cost, SExp_1.SExp.null()); -} -exports.default_unknown_op = default_unknown_op; -exports.QUOTE_ATOM = __type_compatibility__1.Bytes.from(exports.KEYWORD_TO_ATOM["q"], "hex"); -exports.APPLY_ATOM = __type_compatibility__1.Bytes.from(exports.KEYWORD_TO_ATOM["a"], "hex"); -function merge(obj1, obj2) { - Object.keys(obj2).forEach(key => { - obj1[key] = obj2[key]; - }); -} -function OperatorDict(atom_op_function_map, option = {}) { - const dict = Object.assign(Object.assign({}, atom_op_function_map), { quote_atom: option.quote_atom || atom_op_function_map.quote_atom, apply_atom: option.apply_atom || atom_op_function_map.apply_atom, unknown_op_handler: option.unknown_op_handler || default_unknown_op }); - if (!dict.quote_atom) { - throw new Error("object has not attribute 'quote_atom'"); - } - else if (!dict.apply_atom) { - throw new Error("object has not attribute 'apply_atom'"); - } - const OperatorDict = function (op, args) { - if (typeof op === "string") { - op = __type_compatibility__1.Bytes.from(op, "hex"); - } - else if (typeof op === "number") { - op = __type_compatibility__1.Bytes.from([op]); - } - else if (!__type_compatibility__1.isBytes(op)) { - throw new Error(`Invalid op: ${JSON.stringify(op)}`); - } - merge(dict, OperatorDict); - const f = dict[op.hex()]; - if (typeof f !== "function") { - return dict.unknown_op_handler(op, args); - } - else { - return f(args); - } - }; - merge(OperatorDict, dict); - return OperatorDict; -} -exports.OperatorDict = OperatorDict; -const _OPERATOR_LOOKUP = OperatorDict(op_utils_1.operators_for_module(exports.KEYWORD_TO_ATOM, core_ops, exports.OP_REWRITE), { - quote_atom: exports.QUOTE_ATOM, - apply_atom: exports.APPLY_ATOM, -}); -merge(_OPERATOR_LOOKUP, op_utils_1.operators_for_module(exports.KEYWORD_TO_ATOM, more_ops, exports.OP_REWRITE)); -exports.OPERATOR_LOOKUP = _OPERATOR_LOOKUP; diff --git a/.dist/npm/package.json b/.dist/npm/package.json deleted file mode 100644 index 397b81e..0000000 --- a/.dist/npm/package.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "name": "clvm", - "version": "0.0.19", - "author": "Admin ChiaMineJP ", - "description": "Javascript implementation of chia lisp", - "license": "MIT", - "repository": { - "type": "git", - "url": "https://github.com/Chia-Mine/clvm-js.git" - }, - "bugs": "https://github.com/Chia-Mine/clvm-js/issues", - "main": "./index.js", - "typings": "./index.d.ts", - "scripts": { - "build": "node pre_build.js && tsc --sourcemap false && webpack", - "test": "jest" - }, - "keywords": [ - "chia", - "clvm", - "chialisp", - "typescript" - ], - "engines": { - "node": ">=12.13.0" - }, - "dependencies": { - "@chiamine/bls-signatures": "^0.2.1-beta.1", - "jscrypto": "^1.0.2" - }, - "devDependencies": { - "@types/jest": "^26.0.24", - "@types/node": "^15.0.2", - "@typescript-eslint/eslint-plugin": "^4.1.0", - "@typescript-eslint/parser": "^4.1.0", - "eslint": "^7.8.1", - "eslint-plugin-import": "^2.22.0", - "eslint-plugin-jsdoc": "^30.4.1", - "fork-ts-checker-webpack-plugin": "^6.2.12", - "jest": "^27.0.6", - "terser-webpack-plugin": "^5.1.3", - "ts-jest": "^27.0.3", - "ts-loader": "^9.2.3", - "typescript": "^4.2.4", - "webpack": "^5.39.1", - "webpack-cli": "^4.7.2" - } -} \ No newline at end of file diff --git a/.dist/npm/run_program.d.ts b/.dist/npm/run_program.d.ts deleted file mode 100644 index a5fb458..0000000 --- a/.dist/npm/run_program.d.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { int, None, uint8 } from "./__python_types__"; -import { SExp } from "./SExp"; -import { TToSexpF } from "./as_javascript"; -import { CLVMObject } from "./CLVMObject"; -import { Tuple } from "./__type_compatibility__"; -import { TOperatorDict } from "./operators"; -export declare type OpCallable = (opStack: OpStackType, valStack: ValStackType) => int; -export declare type ValStackType = SExp[]; -export declare type OpStackType = OpCallable[]; -export declare type TPreEvalF = (v1: SExp, v2: SExp) => unknown; -export declare function to_pre_eval_op(pre_eval_f: TPreEvalF, to_sexp_f: TToSexpF): (op_stack: OpStackType, value_stack: ValStackType) => void; -export declare function msb_mask(byte: uint8): number; -export declare function run_program(program: SExp, args: CLVMObject, operator_lookup: TOperatorDict, max_cost?: number | None, pre_eval_f?: TPreEvalF | None): Tuple; diff --git a/.dist/npm/run_program.js b/.dist/npm/run_program.js deleted file mode 100644 index 2f996a9..0000000 --- a/.dist/npm/run_program.js +++ /dev/null @@ -1,167 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.run_program = exports.msb_mask = exports.to_pre_eval_op = void 0; -const __python_types__1 = require("./__python_types__"); -const SExp_1 = require("./SExp"); -const CLVMObject_1 = require("./CLVMObject"); -const __type_compatibility__1 = require("./__type_compatibility__"); -const costs_1 = require("./costs"); -const EvalError_1 = require("./EvalError"); -function to_pre_eval_op(pre_eval_f, to_sexp_f) { - return function my_pre_eval_op(op_stack, value_stack) { - const v = to_sexp_f(value_stack[value_stack.length - 1]); - const context = pre_eval_f(v.first(), v.rest()); - if (typeof context === "function") { - const invoke_context_op = (op_stack, value_stack) => { - context(to_sexp_f(value_stack[value_stack.length - 1])); - return 0; - }; - op_stack.push(invoke_context_op); - } - }; -} -exports.to_pre_eval_op = to_pre_eval_op; -function msb_mask(byte) { - byte |= byte >> 1; - byte |= byte >> 2; - byte |= byte >> 4; - return (byte + 1) >> 1; -} -exports.msb_mask = msb_mask; -function run_program(program, args, operator_lookup, max_cost = __python_types__1.None, pre_eval_f = __python_types__1.None) { - program = SExp_1.SExp.to(program); - const pre_eval_op = pre_eval_f ? to_pre_eval_op(pre_eval_f, SExp_1.SExp.to) : __python_types__1.None; - function traverse_path(sexp, env) { - let cost = costs_1.PATH_LOOKUP_BASE_COST; - cost += costs_1.PATH_LOOKUP_COST_PER_LEG; - if (sexp.nullp()) { - return __type_compatibility__1.t(cost, SExp_1.SExp.null()); - } - const b = sexp.atom; - let end_byte_cursor = 0; - while (end_byte_cursor < b.length && b.get_byte_at(end_byte_cursor) === 0) { - end_byte_cursor += 1; - } - cost += end_byte_cursor * costs_1.PATH_LOOKUP_COST_PER_ZERO_BYTE; - if (end_byte_cursor === b.length) { - return __type_compatibility__1.t(cost, SExp_1.SExp.null()); - } - // # create a bitmask for the most significant *set* bit - // # in the last non-zero byte - const end_bitmask = msb_mask(b.get_byte_at(end_byte_cursor)); - let byte_cursor = b.length - 1; - let bitmask = 0x01; - while (byte_cursor > end_byte_cursor || bitmask < end_bitmask) { - if (!CLVMObject_1.isCons(env)) { - throw new EvalError_1.EvalError("path into atom", env); - } - if (b.get_byte_at(byte_cursor) & bitmask) { - env = env.rest(); - } - else { - env = env.first(); - } - cost += costs_1.PATH_LOOKUP_COST_PER_LEG; - bitmask <<= 1; - if (bitmask === 0x0100) { - byte_cursor -= 1; - bitmask = 0x01; - } - } - return __type_compatibility__1.t(cost, env); - } - function swap_op(op_stack, value_stack) { - const v2 = value_stack.pop(); - const v1 = value_stack.pop(); - value_stack.push(v2); - value_stack.push(v1); - return 0; - } - function cons_op(op_stack, value_stack) { - const v1 = value_stack.pop(); - const v2 = value_stack.pop(); - value_stack.push(v1.cons(v2)); - return 0; - } - function eval_op(op_stack, value_stack) { - if (pre_eval_op) { - pre_eval_op(op_stack, value_stack); - } - const pair = value_stack.pop(); - const sexp = pair.first(); - const args = pair.rest(); - // # put a bunch of ops on op_stack - if (!CLVMObject_1.isCons(sexp)) { - // # sexp is an atom - const [cost, r] = traverse_path(sexp, args); - value_stack.push(r); - return cost; - } - const operator = sexp.first(); - if (CLVMObject_1.isCons(operator)) { - const pair = operator.as_pair(); - const [new_operator, must_be_nil] = pair; - if (new_operator.pair || !__type_compatibility__1.Bytes.NULL.equal_to(must_be_nil.atom)) { - throw new EvalError_1.EvalError("in ((X)...) syntax X must be lone atom", sexp); - } - const new_operand_list = sexp.rest(); - value_stack.push(new_operator); - value_stack.push(new_operand_list); - op_stack.push(apply_op); - return costs_1.APPLY_COST; - } - const op = operator.atom; - let operand_list = sexp.rest(); - // op === operator_lookup.quote_atom - if (op.equal_to(operator_lookup.quote_atom)) { - value_stack.push(operand_list); - return costs_1.QUOTE_COST; - } - op_stack.push(apply_op); - value_stack.push(operator); - while (!operand_list.nullp()) { - const _ = operand_list.first(); - value_stack.push(_.cons(args)); - op_stack.push(cons_op); - op_stack.push(eval_op); - op_stack.push(swap_op); - operand_list = operand_list.rest(); - } - value_stack.push(SExp_1.SExp.null()); - return 1; - } - function apply_op(op_stack, value_stack) { - const operand_list = value_stack.pop(); - const operator = value_stack.pop(); - if (!CLVMObject_1.isAtom(operator)) { - throw new EvalError_1.EvalError("internal error", operator); - } - const op = operator.atom; - // op === operator_lookup.apply_atom - if (op.equal_to(operator_lookup.apply_atom)) { - if (operand_list.list_len() !== 2) { - throw new EvalError_1.EvalError("apply requires exactly 2 parameters", operand_list); - } - const new_program = operand_list.first(); - const new_args = operand_list.rest().first(); - value_stack.push(new_program.cons(new_args)); - op_stack.push(eval_op); - return costs_1.APPLY_COST; - } - const [additional_cost, r] = operator_lookup(op, operand_list); - value_stack.push(r); - return additional_cost; - } - const op_stack = [eval_op]; - const value_stack = [program.cons(args)]; - let cost = 0; - while (op_stack.length) { - const f = op_stack.pop(); - cost += f(op_stack, value_stack); - if (max_cost && cost > max_cost) { - throw new EvalError_1.EvalError("cost exceeded", SExp_1.SExp.to(max_cost)); - } - } - return __type_compatibility__1.t(cost, value_stack[value_stack.length - 1]); -} -exports.run_program = run_program; diff --git a/.dist/npm/serialize.d.ts b/.dist/npm/serialize.d.ts deleted file mode 100644 index 4810f5c..0000000 --- a/.dist/npm/serialize.d.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { SExp } from "./SExp"; -import { Bytes, Stream } from "./__type_compatibility__"; -import { None } from "./__python_types__"; -import { TToSexpF } from "./as_javascript"; -export declare function sexp_to_byte_iterator(sexp: SExp): Generator; -export declare function atom_to_byte_iterator(atom: Bytes | None): Generator; -export declare function sexp_to_stream(sexp: SExp, f: Stream): void; -export declare function sexp_from_stream(f: Stream, to_sexp_f: TToSexpF): SExp; -export declare function sexp_buffer_from_stream(f: Stream): Bytes; diff --git a/.dist/npm/serialize.js b/.dist/npm/serialize.js deleted file mode 100644 index ec07834..0000000 --- a/.dist/npm/serialize.js +++ /dev/null @@ -1,211 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.sexp_buffer_from_stream = exports.sexp_from_stream = exports.sexp_to_stream = exports.atom_to_byte_iterator = exports.sexp_to_byte_iterator = void 0; -const __type_compatibility__1 = require("./__type_compatibility__"); -const casts_1 = require("./casts"); -const CLVMObject_1 = require("./CLVMObject"); -const MAX_SINGLE_BYTE = 0x7F; -const CONS_BOX_MARKER = 0xFF; -function* sexp_to_byte_iterator(sexp) { - const todo_stack = [sexp]; - while (todo_stack.length) { - sexp = todo_stack.pop(); - const pair = sexp.as_pair(); - if (pair) { - // yield Bytes.from([CONS_BOX_MARKER]); - yield new __type_compatibility__1.Bytes(new Uint8Array([CONS_BOX_MARKER])); - todo_stack.push(pair[1]); - todo_stack.push(pair[0]); - } - else { - yield* atom_to_byte_iterator(sexp.atom); - } - } -} -exports.sexp_to_byte_iterator = sexp_to_byte_iterator; -function* atom_to_byte_iterator(atom) { - const size = atom ? atom.length : 0; - if (size === 0 || !atom) { - // yield Bytes.from("0x80", "hex"); - yield new __type_compatibility__1.Bytes(new Uint8Array([0x80])); - return; - } - else if (size === 1) { - if (atom.get_byte_at(0) <= MAX_SINGLE_BYTE) { - yield atom; - return; - } - } - let uint8array; - if (size < 0x40) { - uint8array = Uint8Array.from([0x80 | size]); - } - else if (size < 0x2000) { - uint8array = Uint8Array.from([ - 0xC0 | (size >> 8), - (size >> 0) & 0xFF, - ]); - } - else if (size < 0x100000) { - uint8array = Uint8Array.from([ - 0xE0 | (size >> 16), - (size >> 8) & 0xFF, - (size >> 0) & 0xFF, - ]); - } - else if (size < 0x8000000) { - uint8array = Uint8Array.from([ - 0xF0 | (size >> 24), - (size >> 16) & 0xFF, - (size >> 8) & 0xFF, - (size >> 0) & 0xFF, - ]); - } - else if (size < 0x400000000) { - uint8array = Uint8Array.from([ - 0xF8 | ((size / 2 ** 32) >> 0), - ((size / 2 ** 24) >> 0) & 0xFF, - ((size / 2 ** 16) >> 0) & 0xFF, - ((size / 2 ** 8) >> 0) & 0xFF, - ((size / 2 ** 0) >> 0) & 0xFF, - ]); - } - else { - throw new Error(`sexp too long ${atom}`); - } - const size_blob = new __type_compatibility__1.Bytes(uint8array); - yield size_blob; - yield atom; - return; -} -exports.atom_to_byte_iterator = atom_to_byte_iterator; -function sexp_to_stream(sexp, f) { - for (const b of sexp_to_byte_iterator(sexp)) { - f.write(b); - } -} -exports.sexp_to_stream = sexp_to_stream; -function _op_read_sexp(op_stack, val_stack, f, to_sexp_f) { - const blob = f.read(1); - if (blob.length === 0) { - throw new Error("bad encoding"); - } - const b = blob.get_byte_at(0); - if (b === CONS_BOX_MARKER) { - op_stack.push(_op_cons); - op_stack.push(_op_read_sexp); - op_stack.push(_op_read_sexp); - return; - } - val_stack.push(_atom_from_stream(f, b, to_sexp_f)); -} -function _op_cons(op_stack, val_stack, f, to_sexp_f) { - const right = val_stack.pop(); - const left = val_stack.pop(); - val_stack.push(to_sexp_f(__type_compatibility__1.t(left, right))); -} -function sexp_from_stream(f, to_sexp_f) { - const op_stack = [_op_read_sexp]; - const val_stack = []; - while (op_stack.length) { - const func = op_stack.pop(); - if (func) { - func(op_stack, val_stack, f, ((v) => new CLVMObject_1.CLVMObject(v))); - } - } - return to_sexp_f(val_stack.pop()); -} -exports.sexp_from_stream = sexp_from_stream; -function _op_consume_sexp(f) { - const blob = f.read(1); - if (blob.length === 0) { - throw new Error("bad encoding"); - } - const b = blob.get_byte_at(0); - if (b === CONS_BOX_MARKER) { - return __type_compatibility__1.t(blob, 2); - } - return __type_compatibility__1.t(_consume_atom(f, b), 0); -} -function _consume_atom(f, b) { - if (b === 0x80) { - return __type_compatibility__1.Bytes.from([b]); - } - else if (b <= MAX_SINGLE_BYTE) { - return __type_compatibility__1.Bytes.from([b]); - } - let bit_count = 0; - let bit_mask = 0x80; - let ll = b; - while (ll & bit_mask) { - bit_count += 1; - ll &= 0xFF ^ bit_mask; - bit_mask >>= 1; - } - let size_blob = __type_compatibility__1.Bytes.from([ll]); - if (bit_count > 1) { - const ll2 = f.read(bit_count - 1); - if (ll2.length !== bit_count - 1) { - throw new Error("bad encoding"); - } - size_blob = size_blob.concat(ll2); - } - const size = casts_1.int_from_bytes(size_blob); - if (size >= 0x400000000) { - throw new Error("blob too large"); - } - const blob = f.read(size); - if (blob.length !== size) { - throw new Error("bad encoding"); - } - return __type_compatibility__1.Bytes.from([b]).concat(size_blob.slice(1)).concat(blob); -} -/* -# instead of parsing the input stream, this function pulls out all the bytes -# that represent on S-expression tree, and returns them. This is more efficient -# than parsing and returning a python S-expression tree. - */ -function sexp_buffer_from_stream(f) { - const buffer = new __type_compatibility__1.Stream(); - let depth = 1; - while (depth > 0) { - depth -= 1; - const [buf, d] = _op_consume_sexp(f); - depth += d; - buffer.write(buf); - } - return buffer.getValue(); -} -exports.sexp_buffer_from_stream = sexp_buffer_from_stream; -function _atom_from_stream(f, b, to_sexp_f) { - if (b === 0x80) { - return to_sexp_f(__type_compatibility__1.Bytes.NULL); - } - else if (b <= MAX_SINGLE_BYTE) { - return to_sexp_f(__type_compatibility__1.Bytes.from([b])); - } - let bit_count = 0; - let bit_mask = 0x80; - while (b & bit_mask) { - bit_count += 1; - b &= 0xFF ^ bit_mask; - bit_mask >>= 1; - } - let size_blob = __type_compatibility__1.Bytes.from([b]); - if (bit_count > 1) { - const bin = f.read(bit_count - 1); - if (bin.length !== bit_count - 1) { - throw new Error("bad encoding"); - } - size_blob = size_blob.concat(bin); - } - const size = casts_1.int_from_bytes(size_blob); - if (size >= 0x400000000) { - throw new Error("blob too large"); - } - const blob = f.read(size); - if (blob.length !== size) { - throw new Error("bad encoding"); - } - return to_sexp_f(blob); -} diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..9053287 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,48 @@ +name: Test + +on: + push: + branches: + - main + tags: + - '**' + pull_request: + branches: + - '**' + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Setup Node 14 + uses: actions/setup-node@v1 + with: + node-version: '14.x' + + - name: Get yarn version + run: echo "yarn_version=$(yarn -v)" >> $GITHUB_ENV + + - name: Get yarn(v1) cache directory path + if: startsWith(env.yarn_version, '1') + run: echo "cache_dir=$(yarn cache dir)" >> $GITHUB_ENV + + - name: Get yarn(v2) cache directory path + if: startsWith(env.yarn_version, '2') + run: echo "cache_dir=$(yarn config get cacheFolder)" + + - name: Cache Node.js modules + id: yarn-cache + uses: actions/cache@v2 + with: + path: ${{ env.cache_dir }} + key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-yarn- + + - name: Install dependencies + run: yarn --frozen-lockfile + + - run: yarn build + - run: yarn test \ No newline at end of file diff --git a/.gitignore b/.gitignore index 39445b0..fde3686 100644 --- a/.gitignore +++ b/.gitignore @@ -258,3 +258,4 @@ $RECYCLE.BIN/ .npmrc build/ playground/ +.dist/ diff --git a/CHANGELOG.md b/CHANGELOG.md index 65aacf4..d4130ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,21 @@ # Changelog +## [1.0.0] +This version is compatible with [`1a5cb17895d8707f784a85180bc97d3c6ebe71a0`](https://github.com/Chia-Network/clvm/tree/1a5cb17895d8707f784a85180bc97d3c6ebe71a0) of [clvm@0.9.7](https://github.com/Chia-Network/clvm) + +### Removed +- Removed `.dist` folder from git. + - This folder made it harder to check diffs between versions. +### Added +- Added GitHub Action +- Added `str()`, `repr()` utility functions. +- Added `Bytes::subarray` to get bytes data without additional memory allocation/copy. +### Changed +- Updated README.md +- Changed method name `Bytes::get_byte_at` to `Bytes::at` (Breaking change). +### Deprecated +- Deprecated python specific type definition such as `str`, `int`. Use `string`, `number` instead. + ## [0.0.19] **There are 2 breaking changes.** @@ -148,6 +164,7 @@ At this version, I've managed to improve test complete time to `79s` -> `2s` by Initial (beta) release. +[1.0.0]: https://github.com/Chia-Mine/clvm-js/compare/v0.0.19...v1.0.0 [0.0.19]: https://github.com/Chia-Mine/clvm-js/compare/v0.0.18...v0.0.19 [0.0.18]: https://github.com/Chia-Mine/clvm-js/compare/v0.0.17...v0.0.18 [0.0.17]: https://github.com/Chia-Mine/clvm-js/compare/v0.0.16...v0.0.17 diff --git a/README.md b/README.md index 7ee6bf4..8edb14f 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,6 @@ # clvm Javascript implementation of CLVM (Chia Lisp VM) -Still Work in progress.(Untested) - -**v0.x.x is test purpose only!** -Please report bugs to https://github.com/Chia-Mine/clvm-js/issues ## Install ```shell @@ -13,6 +9,11 @@ npm install clvm yarn add clvm ``` +## Compatibility +This code is compatible with: +- [`1a5cb17895d8707f784a85180bc97d3c6ebe71a0`](https://github.com/Chia-Network/clvm/tree/1a5cb17895d8707f784a85180bc97d3c6ebe71a0) of [clvm@0.9.7](https://github.com/Chia-Network/clvm) + - [Diff to the latest clvm](https://github.com/Chia-Network/clvm/compare/1a5cb17895d8707f784a85180bc97d3c6ebe71a0...main) + ## Example ```javascript // in nodejs context @@ -56,6 +57,92 @@ you need to put `blsjs.wasm` to the same directory as the code who loads `clvm`. If so, you can make your code fully synchronous. +## Differences with Python's `clvm` +Although I try hard to make it look like Python's `clvm`, there are things users should take it into account. +I put the code which absorbs language incompatibility into `src/__type_compaibility__.ts`, so if you're interested take a look at it. + +### There are no build-in `Tuple` type in Javascript +When you want to create a tuple, you need to write like this: +```javascript +const {t} = require("clvm"); +const aTuple = t(1, 2); + +// Tuple is Array-Like object +aTuple[0] === 1; // true +aTuple[1] === 2; // true + +// Tuple content cannot be changed +aTuple[0] = 99; +aTuple[0] === 99; // false +aTuple[0] === 1; // true + +// Tuple accepts only 2 elements. +const tuple2 = t(1, 2, 3); +tuple2; // (1, 2) + +// You can check if a variable is a tuple +const {isTuple} = require("clvm"); +isTuple([1, 2]); // false +isTuple(t(1, 2)); // true +``` +Just add `t` in front of tuple parenthesis `(1, 2)` and you get a tuple. + +### There are no build-in `bytes` type in JavaScript +This is the most notable difference with Python. +I used to be a JavaScript developer for several years, and sometimes I heard Python is slow and JavaScript is fast. +But working on the project, I truly surprised that Python can handle byte data really well in ways: +- Python's `bytes` is **immutable** and can be used as a dict key. +- Python's `bytes` is fast and easy to write. + `b'aaa' + b'bbb' == b'aaabbb'`, `b'a' * 3 == b'aaa'` +- Python's `bytes` comparison is FAST. + If you are interested, compare the performance of `test_very_long_blobs` in `tests/serialize_test.[ts|py]` + See more details [here](https://github.com/Chia-Network/clvm/pull/100) + +```javascript +const {b} = require("clvm"); +// Turns string to UTF-8 byte array. +b("abc"); // will be { Uint8Array(3) [97,98,99] } +b("あ"); // will be { Uint8Array(3) [227,129,130] } + +// If you want to do Byte comparison, use equal_to method. +b("abc").equal_to(b("abc")); // true +b("abc") === b("abc"); // false. Because it compares reference of Bytes instance. + +// Initialize Bytes instance with hex string +const {h} = require("clvm"); +h("0x616263"); // will be { Uint8Array(3) [97,98,99] } +h("616263"); // You can omit '0x' prefix +h("0x616263").equal_to(b("abc")); // true + +// +: Bytes concat +b("a").concat(b("b")); // === b("ab") +// *: Bytes repeat +b("a").repeat(3); // === b("aaa") + +// Bytes initialization +const {Bytes} = require("clvm"); +uint8 = new Uint8Array([97, 98, 99]); +b1 = Bytes.from(uint8); +b1.equal_to(b("abc")); // true +// Initializing by Bytes.from copies value and cut reference apart. +uint8[0] = 0; +b1.at(0); // 97 +// Initializing by new Bytes() just stores value and keep reference, for better performance +uint8 = new Uint8Array([97, 98, 99]); +b2 = new Bytes(uint8); +b2.equal_to(b("abc")); // true +uint8[0] = 0; +b2.at(0); // 0 +``` + +### Python's `str(x)` is `x.toString()` in Javascript +If you want to stringify `SExp` or `Bytes`, just call `x.toString()` method. +```javascript +const {b, SExp, str} = require("clvm"); +b("あ").toString(); // "b'\\xe3\\x81\\x82'" +SExp.to([1, [2, 3]]).toString(); // 'ff01ffff02ff038080' +str(SExp.to([1, [2, 3]])); // You can use str() function as well as Python by the way. +``` ## clvm license `clvm-js` is based on [clvm](https://github.com/Chia-Network/clvm) with the diff --git a/package.json b/package.json index aff808a..8b94e40 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "clvm", - "version": "0.0.19", + "version": "1.0.0", "author": "Admin ChiaMineJP ", "description": "Javascript implementation of chia lisp", "license": "MIT", diff --git a/pre_build.js b/pre_build.js index 7d9d0df..29975c6 100644 --- a/pre_build.js +++ b/pre_build.js @@ -2,14 +2,16 @@ const path = require("path"); const fs = require("fs"); // clean and create output dir -const distDir = path.join(__dirname, ".dist", "npm"); +const distDir = path.join(__dirname, ".dist"); if(fs.existsSync(distDir)){ fs.rmdirSync(distDir, {recursive: true}); } fs.mkdirSync(distDir); +const distNpmDir = path.join(distDir, "npm"); +fs.mkdirSync(distNpmDir); // Copy wasm file -const browserDir = path.join(distDir, "browser"); +const browserDir = path.join(distNpmDir, "browser"); if(fs.existsSync(browserDir)){ fs.rmdirSync(browserDir, {recursive: true}); } @@ -26,11 +28,11 @@ fs.copyFileSync(blsWasmSrcPath, blsWasmDestPath); const packageJson = require("./package.json"); -fs.writeFileSync(path.join(distDir, "package.json"), JSON.stringify(packageJson, null, 2)); +fs.writeFileSync(path.join(distNpmDir, "package.json"), JSON.stringify(packageJson, null, 2)); function copyFileToPublish(fileName){ const srcPath = path.join(__dirname, fileName); - const distPath = path.join(distDir, fileName); + const distPath = path.join(distNpmDir, fileName); if(fs.existsSync(srcPath)){ fs.copyFileSync(srcPath, distPath); } diff --git a/src/EvalError.ts b/src/EvalError.ts index 90db00c..cbf3974 100644 --- a/src/EvalError.ts +++ b/src/EvalError.ts @@ -1,11 +1,10 @@ -import type {str} from "./__python_types__"; import type {CLVMObject} from "./CLVMObject"; export class EvalError extends Error { public _sexp?: CLVMObject; name = "EvalError"; - public constructor(message: str, sexp: CLVMObject) { + public constructor(message: string, sexp: CLVMObject) { super(message); this._sexp = sexp; } diff --git a/src/SExp.ts b/src/SExp.ts index 7cbbcb2..fbea89c 100644 --- a/src/SExp.ts +++ b/src/SExp.ts @@ -1,5 +1,5 @@ import {G1Element} from "@chiamine/bls-signatures"; -import {int, None, Optional, str} from "./__python_types__"; +import {None, Optional} from "./__python_types__"; import {CLVMObject, CLVMType} from "./CLVMObject"; import {Bytes, isIterable, Tuple, t, Stream, isBytes, isTuple} from "./__type_compatibility__"; import {int_from_bytes, int_to_bytes} from "./casts"; @@ -10,8 +10,8 @@ import {EvalError} from "./EvalError"; export type CastableType = SExp | CLVMType | Bytes -| str -| int +| string +| number | None | G1Element | CastableType[] @@ -210,7 +210,7 @@ export class SExp implements CLVMType { } public nullp(){ - return this.atom !== None && this.atom.raw().length === 0; + return this.atom !== None && this.atom.length === 0; } public as_int(){ diff --git a/src/__python_types__.ts b/src/__python_types__.ts index 2afe73e..bdb52cb 100644 --- a/src/__python_types__.ts +++ b/src/__python_types__.ts @@ -1,3 +1,4 @@ +/* export type int = number; export type int8 = number; export type uint8 = number; @@ -9,14 +10,12 @@ export type int64 = BigInt; export type uint64 = BigInt; export type uint128 = BigInt; export type int512 = BigInt; - export type float = number; - export type str = string; export type bool = boolean; - export type True = true; export type False = false; +*/ export const None = null; // eslint-disable-next-line no-redeclare export type None = null; diff --git a/src/__type_compatibility__.ts b/src/__type_compatibility__.ts index e487ed3..19e6f95 100644 --- a/src/__type_compatibility__.ts +++ b/src/__type_compatibility__.ts @@ -2,7 +2,7 @@ import {Hex} from "jscrypto/Hex"; import {Utf8} from "jscrypto/Utf8"; import {Word32Array} from "jscrypto/Word32Array"; import {SHA256} from "jscrypto/SHA256"; -import {None, str} from "./__python_types__"; +import {None} from "./__python_types__"; import {G1Element} from "@chiamine/bls-signatures"; export function to_hexstr(r: Uint8Array) { @@ -85,7 +85,7 @@ export class Bytes { } } - public static from(value?: Uint8Array|Bytes|number[]|str|G1Element|None, type?: BytesFromType){ + public static from(value?: Uint8Array|Bytes|number[]|string|G1Element|None, type?: BytesFromType){ if(value === None || value === undefined){ return new Bytes(value); } @@ -121,7 +121,7 @@ export class Bytes { throw new Error(`Invalid value: ${JSON.stringify(value)}`); } - public static SHA256(value: str|Bytes|Uint8Array){ + public static SHA256(value: string|Bytes|Uint8Array){ let w; if(typeof value === "string"){ w = SHA256.hash(value); @@ -145,7 +145,7 @@ export class Bytes { return this._b.length; } - public get_byte_at(i: number){ + public at(i: number){ return this._b[i] | 0; } @@ -168,7 +168,14 @@ export class Bytes { public slice(start: number, length?: number){ const len = typeof length === "number" ? length : (this.length - start); - return new Bytes(this._b.slice(start, start+len)); + const ui8_clone = this._b.slice(start, start+len); + return new Bytes(ui8_clone); + } + + public subarray(start: number, length?: number){ + const len = typeof length === "number" ? length : (this.length - start); + const ui8_raw = this._b.subarray(start, start+len); + return new Bytes(ui8_raw); } public as_word(){ @@ -231,8 +238,10 @@ export class Bytes { if(this.length !== other.length){ return this.length > other.length ? 1 : -1; } - const dv_self = new DataView(this.raw().buffer); - const dv_other = new DataView(other.raw().buffer); + const self_raw_byte = this._b; + const dv_self = new DataView(self_raw_byte.buffer, self_raw_byte.byteOffset, self_raw_byte.byteLength); + const other_raw_byte = other.raw(); + const dv_other = new DataView(other_raw_byte.buffer, other_raw_byte.byteOffset, other_raw_byte.byteLength); const ui32MaxCount = (this.length / 4) | 0; for(let i=0;i(iterable: Iterable){ return arr; } +export function str(x: any){ + if(typeof x.toString === "function"){ + return x.toString(); + } + return `${x}`; +} + +export function repr(x: any){ + if(typeof x.__repr__ === "function"){ + return x.__repr__(); + } + return str(x); +} + export class Tuple extends Array { public constructor(...items: [T1, T2]) { super(...items); @@ -314,7 +337,7 @@ export function isIterable(v: any): v is unknown[] { export function isBytes(v: any): v is Bytes { return v && typeof v.length === "number" - && typeof v.get_byte_at === "function" + && typeof v.at === "function" && typeof v.raw === "function" && typeof v.data === "function" && typeof v.hex === "function" @@ -404,7 +427,7 @@ export class Stream { } if(this.seek + size <= this.length){ - const u8 = this._buffer.slice(this.seek, this.seek + size); + const u8 = this._buffer.subarray(this.seek, this.seek + size); this.seek += size; return new Bytes(u8); } diff --git a/src/casts.ts b/src/casts.ts index dc69760..80fe4ec 100644 --- a/src/casts.ts +++ b/src/casts.ts @@ -1,21 +1,21 @@ -import {int, None} from "./__python_types__"; +import {None} from "./__python_types__"; import {Bytes, h} from "./__type_compatibility__"; // In javascript, max safe integer is 2**53-1 (53bit) // Surprisingly, parseInt() can parse over 32bit integer. -export function int_from_bytes(b: Bytes|None): int { +export function int_from_bytes(b: Bytes|None): number { if(!b || b.length === 0){ return 0; } const unsigned32 = parseInt(b.hex(), 16); // If the first bit is 1, it is recognized as a negative number. - if(b.get_byte_at(0) & 0x80){ + if(b.at(0) & 0x80){ return unsigned32 - (1 << (b.length*8)); } return unsigned32; } -export function int_to_bytes(v: int): Bytes { +export function int_to_bytes(v: number): Bytes { if(v > Number.MAX_SAFE_INTEGER || v < Number.MIN_SAFE_INTEGER){ throw new Error(`The int value is beyond ${v > 0 ? "MAX_SAFE_INTEGER" : "MIN_SAFE_INTEGER"}: ${v}`); } @@ -41,8 +41,8 @@ export function int_to_bytes(v: int): Bytes { /** * Return the number of bytes required to represent this integer. - * @param {int} v + * @param {number} v */ -export function limbs_for_int(v: int): int { +export function limbs_for_int(v: number): number { return ((v < 0 ? -v : v).toString(2).length + 7) >> 3; } diff --git a/src/more_ops.ts b/src/more_ops.ts index 0f6391f..3c08d4b 100644 --- a/src/more_ops.ts +++ b/src/more_ops.ts @@ -41,12 +41,11 @@ import { } from "./costs"; import {Bytes, Stream, t, Tuple} from "./__type_compatibility__"; import {EvalError} from "./EvalError"; -import {int, str} from "./__python_types__"; import {int_from_bytes, limbs_for_int} from "./casts"; import {isAtom} from "./CLVMObject"; import {G1Element_add, G1Element_from_bytes, getBLSModule} from "./__bls_signatures__"; -export function malloc_cost(cost: int, atom: SExp){ +export function malloc_cost(cost: number, atom: SExp){ if(!atom.atom){ throw new EvalError("atom is None", atom); } @@ -71,7 +70,7 @@ export function op_sha256(args: SExp){ return malloc_cost(cost, SExp.to(Bytes.from(h.finalize().toUint8Array()))); } -export function* args_as_ints(op_name: str, args: SExp){ +export function* args_as_ints(op_name: string, args: SExp){ for(const arg of args.as_iter()){ if(arg.pair || !arg.atom){ throw new EvalError(`${op_name} requires int args`, arg); @@ -80,7 +79,7 @@ export function* args_as_ints(op_name: str, args: SExp){ } } -export function* args_as_int32(op_name: str, args: SExp){ +export function* args_as_int32(op_name: string, args: SExp){ for(const arg of args.as_iter()){ if(arg.pair || !arg.atom){ throw new EvalError(`${op_name} requires int32 args`, arg); @@ -92,7 +91,7 @@ export function* args_as_int32(op_name: str, args: SExp){ } } -export function args_as_int_list(op_name: str, args: SExp, count: int){ +export function args_as_int_list(op_name: string, args: SExp, count: number){ const int_list: Array> = []; for(const _ of args_as_ints(op_name, args)) int_list.push(_); @@ -103,7 +102,7 @@ export function args_as_int_list(op_name: str, args: SExp, count: int){ return int_list; } -export function* args_as_bools(op_name: str, args: SExp){ +export function* args_as_bools(op_name: string, args: SExp){ for(const arg of args.as_iter()){ const v = arg.atom; if(v?.equal_to(Bytes.NULL)){ @@ -115,7 +114,7 @@ export function* args_as_bools(op_name: str, args: SExp){ } } -export function args_as_bool_list(op_name: str, args: SExp, count: int){ +export function args_as_bool_list(op_name: string, args: SExp, count: number){ const bool_list: SExp[] = []; for(const _ of args_as_bools(op_name, args)) bool_list.push(_); @@ -301,7 +300,7 @@ export function op_substr(args: SExp){ throw new EvalError("invalid indices for substr", args); } - const s = s0.slice(i1, i2); + const s = s0.subarray(i1, i2); const cost = 1; return t(cost, SExp.to(s)); } @@ -369,7 +368,7 @@ export function op_lsh(args: SExp){ } // eslint-disable-next-line @typescript-eslint/ban-types -export function binop_reduction(op_name: str, initial_value: number, args: SExp, op_f: Function){ +export function binop_reduction(op_name: string, initial_value: number, args: SExp, op_f: Function){ let total = initial_value; let arg_size = 0; let cost = LOG_BASE_COST; @@ -384,7 +383,7 @@ export function binop_reduction(op_name: str, initial_value: number, args: SExp, } export function op_logand(args: SExp){ - const binop = (a: int, b: int) => { + const binop = (a: number, b: number) => { a &= b; return a; } @@ -393,7 +392,7 @@ export function op_logand(args: SExp){ } export function op_logior(args: SExp){ - const binop = (a: int, b: int) => { + const binop = (a: number, b: number) => { a |= b; return a; } @@ -402,7 +401,7 @@ export function op_logior(args: SExp){ } export function op_logxor(args: SExp){ - const binop = (a: int, b: int) => { + const binop = (a: number, b: number) => { a ^= b; return a; } diff --git a/src/op_utils.ts b/src/op_utils.ts index 36a175c..9fed9e2 100644 --- a/src/op_utils.ts +++ b/src/op_utils.ts @@ -1,12 +1,11 @@ -import {str} from "./__python_types__"; import {SExp} from "./SExp"; export function operators_for_dict( - keyword_to_atom: Record, - op_dict: Record, - op_name_lookup: Record, + keyword_to_atom: Record, + op_dict: Record, + op_name_lookup: Record, ){ - const d: Record unknown> = {}; + const d: Record unknown> = {}; for(const op of Object.keys(keyword_to_atom)){ const op_name = `op_${op_name_lookup[op] || op}`; const op_f = op_dict[op_name] as (args: SExp) => unknown; @@ -18,9 +17,9 @@ export function operators_for_dict( } export function operators_for_module( - keyword_to_atom: Record, - mod: Record, - op_name_lookup: Record = {}, + keyword_to_atom: Record, + mod: Record, + op_name_lookup: Record = {}, ){ return operators_for_dict(keyword_to_atom, mod, op_name_lookup); } \ No newline at end of file diff --git a/src/operators.ts b/src/operators.ts index cf5cde4..cbc0027 100644 --- a/src/operators.ts +++ b/src/operators.ts @@ -1,4 +1,3 @@ -import {int, str} from "./__python_types__"; import {int_from_bytes} from "./casts"; import {SExp} from "./SExp"; import {Bytes, Tuple, t, isBytes} from "./__type_compatibility__"; @@ -45,13 +44,13 @@ export const KEYWORDS = [ ].join("").trim().split(/\s/); export const KEYWORD_FROM_ATOM = Object .entries(KEYWORDS) - .reduce>((acc, v) => { + .reduce>((acc, v) => { acc[int_to_bytes(+v[0]).toString()] = v[1]; return acc; }, {}); export const KEYWORD_TO_ATOM = Object .entries(KEYWORD_FROM_ATOM) - .reduce>((acc, v) => { + .reduce>((acc, v) => { acc[v[1]] = v[0]; return acc; }, {}); @@ -167,7 +166,7 @@ export const OP_REWRITE = { export type ATOMS = keyof typeof KEYWORD_FROM_ATOM; export type KEYWORDS = keyof typeof KEYWORD_TO_ATOM; -export function* args_len(op_name: str, args: SExp){ +export function* args_len(op_name: string, args: SExp){ for(const arg of args.as_iter()){ if(arg.pair){ throw new EvalError(`${op_name} requires int args"`, arg); @@ -204,10 +203,10 @@ export function* args_len(op_name: str, args: SExp){ # this means that unknown ops where cost_function is 1, 2, or 3, may still be # fatal errors if the arguments passed are not atoms. */ -export function default_unknown_op(op: Bytes, args: SExp): Tuple { +export function default_unknown_op(op: Bytes, args: SExp): Tuple { // # any opcode starting with ffff is reserved (i.e. fatal error) // # opcodes are not allowed to be empty - if(op.length === 0 || op.slice(0, 2).equal_to(Bytes.from("0xffff", "hex"))){ + if(op.length === 0 || op.subarray(0, 2).equal_to(Bytes.from("0xffff", "hex"))){ throw new EvalError("reserved operator", SExp.to(op)); } @@ -216,14 +215,14 @@ export function default_unknown_op(op: Bytes, args: SExp): Tuple> 6; + const cost_function = (op.at(op.length-1) & 0b11000000) >> 6; // # the multiplier cannot be 0. it starts at 1 if(op.length > 5){ throw new EvalError("invalid operator", SExp.to(op)); } - const cost_multiplier = int_from_bytes(op.slice(0, op.length-1)) + 1; + const cost_multiplier = int_from_bytes(op.subarray(0, op.length-1)) + 1; /* # 0 = constant # 1 = like op_add/op_sub @@ -288,7 +287,7 @@ export const APPLY_ATOM = Bytes.from(KEYWORD_TO_ATOM["a"], "hex"); type TOpFunc = (args: SExp) => R; type TBasicAtom = "quote_atom"|"apply_atom"; -type TAtomOpFunctionMap = Record & Partial>; +type TAtomOpFunctionMap = Record & Partial>; function merge(obj1: Record, obj2: Record){ Object.keys(obj2).forEach(key => { @@ -296,10 +295,10 @@ function merge(obj1: Record, obj2: Record){ }); } -export type TOperatorDict = { +export type TOperatorDict = { unknown_op_handler: typeof default_unknown_op; } -& ((op: Bytes|string|number, args: SExp) => Tuple) +& ((op: Bytes|string|number, args: SExp) => Tuple) & TAtomOpFunctionMap & Record ; @@ -310,7 +309,7 @@ export type TOperatorDictOption = { unknown_op_handler: typeof default_unknown_op; }; -export function OperatorDict( +export function OperatorDict( atom_op_function_map: TAtomOpFunctionMap|TOperatorDict, option: Partial = {}, ): TOperatorDict { diff --git a/src/run_program.ts b/src/run_program.ts index 8a36e25..d0395e1 100644 --- a/src/run_program.ts +++ b/src/run_program.ts @@ -1,4 +1,4 @@ -import {int, None, uint8} from "./__python_types__"; +import {None} from "./__python_types__"; import {SExp} from "./SExp"; import {TToSexpF} from "./as_javascript"; import {CLVMObject, isAtom, isCons} from "./CLVMObject"; @@ -13,7 +13,7 @@ import { import {EvalError} from "./EvalError"; import {TOperatorDict} from "./operators"; -export type OpCallable = (opStack: OpStackType, valStack: ValStackType) => int; +export type OpCallable = (opStack: OpStackType, valStack: ValStackType) => number; export type ValStackType = SExp[]; export type OpStackType = OpCallable[]; export type TPreEvalF = (v1: SExp, v2: SExp) => unknown; @@ -33,7 +33,7 @@ export function to_pre_eval_op(pre_eval_f: TPreEvalF, to_sexp_f: TToSexpF){ }; } -export function msb_mask(byte: uint8){ +export function msb_mask(byte: number){ byte |= byte >> 1; byte |= byte >> 2; byte |= byte >> 4; @@ -46,11 +46,11 @@ export function run_program( operator_lookup: TOperatorDict, max_cost: number|None = None, pre_eval_f: TPreEvalF|None = None, -): Tuple{ +): Tuple{ program = SExp.to(program); const pre_eval_op = pre_eval_f ? to_pre_eval_op(pre_eval_f, SExp.to) : None; - function traverse_path(sexp: SExp, env: SExp): Tuple { + function traverse_path(sexp: SExp, env: SExp): Tuple { let cost = PATH_LOOKUP_BASE_COST; cost += PATH_LOOKUP_COST_PER_LEG; if(sexp.nullp()){ @@ -60,7 +60,7 @@ export function run_program( const b = sexp.atom as Bytes; let end_byte_cursor = 0; - while(end_byte_cursor < b.length && b.get_byte_at(end_byte_cursor) === 0){ + while(end_byte_cursor < b.length && b.at(end_byte_cursor) === 0){ end_byte_cursor += 1; } @@ -71,7 +71,7 @@ export function run_program( // # create a bitmask for the most significant *set* bit // # in the last non-zero byte - const end_bitmask = msb_mask(b.get_byte_at(end_byte_cursor)); + const end_bitmask = msb_mask(b.at(end_byte_cursor)); let byte_cursor = b.length - 1; let bitmask = 0x01; @@ -79,7 +79,7 @@ export function run_program( if(!isCons(env)){ throw new EvalError("path into atom", env); } - if(b.get_byte_at(byte_cursor) & bitmask){ + if(b.at(byte_cursor) & bitmask){ env = env.rest(); } else{ @@ -95,7 +95,7 @@ export function run_program( return t(cost, env); } - function swap_op(op_stack: OpStackType, value_stack: ValStackType): int { + function swap_op(op_stack: OpStackType, value_stack: ValStackType): number { const v2 = value_stack.pop() as SExp; const v1 = value_stack.pop() as SExp; value_stack.push(v2); @@ -103,14 +103,14 @@ export function run_program( return 0; } - function cons_op (op_stack: OpStackType, value_stack: ValStackType): int { + function cons_op (op_stack: OpStackType, value_stack: ValStackType): number { const v1 = value_stack.pop() as SExp; const v2 = value_stack.pop() as SExp; value_stack.push(v1.cons(v2)); return 0; } - function eval_op(op_stack: OpStackType, value_stack: ValStackType): int { + function eval_op(op_stack: OpStackType, value_stack: ValStackType): number { if(pre_eval_op){ pre_eval_op(op_stack, value_stack); } @@ -122,7 +122,7 @@ export function run_program( // # put a bunch of ops on op_stack if(!isCons(sexp)){ // # sexp is an atom - const [cost, r] = traverse_path(sexp, args) as [int, SExp]; + const [cost, r] = traverse_path(sexp, args) as [number, SExp]; value_stack.push(r); return cost; } @@ -162,7 +162,7 @@ export function run_program( return 1; } - function apply_op(op_stack: OpStackType, value_stack: ValStackType): int { + function apply_op(op_stack: OpStackType, value_stack: ValStackType): number { const operand_list = value_stack.pop() as SExp; const operator = value_stack.pop() as SExp; if(!isAtom(operator)){ @@ -182,7 +182,7 @@ export function run_program( return APPLY_COST; } - const [additional_cost, r] = operator_lookup(op, operand_list) as [int, CLVMObject]; + const [additional_cost, r] = operator_lookup(op, operand_list) as [number, CLVMObject]; value_stack.push(r as SExp); return additional_cost; } diff --git a/src/serialize.ts b/src/serialize.ts index 2381ec6..436254a 100644 --- a/src/serialize.ts +++ b/src/serialize.ts @@ -49,7 +49,7 @@ export function* atom_to_byte_iterator(atom: Bytes|None){ return; } else if(size === 1){ - if(atom.get_byte_at(0) <= MAX_SINGLE_BYTE){ + if(atom.at(0) <= MAX_SINGLE_BYTE){ yield atom; return; } @@ -110,7 +110,7 @@ function _op_read_sexp(op_stack: TOpStack, val_stack: TValStack, f: Stream, to_s if(blob.length === 0){ throw new Error("bad encoding"); } - const b = blob.get_byte_at(0); + const b = blob.at(0); if(b === CONS_BOX_MARKER){ op_stack.push(_op_cons); op_stack.push(_op_read_sexp); @@ -145,7 +145,7 @@ function _op_consume_sexp(f: Stream){ if(blob.length === 0){ throw new Error("bad encoding"); } - const b = blob.get_byte_at(0); + const b = blob.at(0); if(b === CONS_BOX_MARKER){ return t(blob, 2); } @@ -187,7 +187,7 @@ function _consume_atom(f: Stream, b: number){ if(blob.length !== size){ throw new Error("bad encoding"); } - return Bytes.from([b]).concat(size_blob.slice(1)).concat(blob); + return Bytes.from([b]).concat(size_blob.subarray(1)).concat(blob); } /* diff --git a/tests/as_javascript_test.ts b/tests/as_javascript_test.ts index c0d409e..6f85ef0 100644 --- a/tests/as_javascript_test.ts +++ b/tests/as_javascript_test.ts @@ -1,4 +1,4 @@ -import {SExp, t, h, b, Bytes, getBLSModule, initialize, None, Tuple, list} from "../src"; +import {SExp, t, h, b, Bytes, getBLSModule, initialize, None, Tuple, list, str, repr} from "../src"; import {CLVMObject} from "../src/CLVMObject"; import {EvalError} from "../src/EvalError"; import type {ModuleInstance} from "@chiamine/bls-signatures"; @@ -287,17 +287,17 @@ test("test_eq_tree", () => { }); test("test_str", () => { - expect(SExp.to(1).toString()).toBe("01"); - expect(SExp.to(1337).toString()).toBe("820539"); - expect(SExp.to(-1).toString()).toBe("81ff"); - expect(SExp.to(gen_tree(1)).toString()).toBe("ff820539820539"); - expect(SExp.to(gen_tree(2)).toString()).toBe("ffff820539820539ff820539820539"); + expect(str(SExp.to(1))).toBe("01"); + expect(str(SExp.to(1337))).toBe("820539"); + expect(str(SExp.to(-1))).toBe("81ff"); + expect(str(SExp.to(gen_tree(1)))).toBe("ff820539820539"); + expect(str(SExp.to(gen_tree(2)))).toBe("ffff820539820539ff820539820539"); }); test("test_repr", () => { - expect(SExp.to(1).__repr__()).toBe("SExp(01)"); - expect(SExp.to(1337).__repr__()).toBe("SExp(820539)"); - expect(SExp.to(-1).__repr__()).toBe("SExp(81ff)"); - expect(SExp.to(gen_tree(1)).__repr__()).toBe("SExp(ff820539820539)"); - expect(SExp.to(gen_tree(2)).__repr__()).toBe("SExp(ffff820539820539ff820539820539)"); + expect(repr(SExp.to(1))).toBe("SExp(01)"); + expect(repr(SExp.to(1337))).toBe("SExp(820539)"); + expect(repr(SExp.to(-1))).toBe("SExp(81ff)"); + expect(repr(SExp.to(gen_tree(1)))).toBe("SExp(ff820539820539)"); + expect(repr(SExp.to(gen_tree(2)))).toBe("SExp(ffff820539820539ff820539820539)"); }); diff --git a/tests/serialize_test.ts b/tests/serialize_test.ts index 2b89831..0c327b8 100644 --- a/tests/serialize_test.ts +++ b/tests/serialize_test.ts @@ -18,8 +18,8 @@ class InfiniteStream extends Stream { public read(n: number){ let ret = b(""); while(n > 0 && this._buf.length > 0){ - ret = ret.concat(this._buf.slice(0,1)); - this._buf = this._buf.slice(1); + ret = ret.concat(this._buf.subarray(0,1)); + this._buf = this._buf.subarray(1); n -= 1; } ret = ret.concat(b(" ").repeat(n)); @@ -85,7 +85,7 @@ test("test_long_blobs", () =>{ text = text.repeat(300); for(let _=0;_ { expect(text.length).toBeGreaterThan(size); check_serde(text); } - }); test("test_very_deep_tree", () => { diff --git a/tests/to_sexp_test.ts b/tests/to_sexp_test.ts index 2e8f88c..d8348a3 100644 --- a/tests/to_sexp_test.ts +++ b/tests/to_sexp_test.ts @@ -29,7 +29,7 @@ function print_leaves(tree: SExp): string { if(a.length === 0){ return "() "; } - return `${a.get_byte_at(0)} `; + return `${a.at(0)} `; } let ret = ""; @@ -45,7 +45,7 @@ function print_tree(tree: SExp): string { if(a.length === 0){ return "() "; } - return `${a.get_byte_at(0)} `; + return `${a.at(0)} `; } let ret = "(";