clvm
Version:
Javascript implementation of chia lisp
91 lines (90 loc) • 3.23 kB
TypeScript
import { Word32Array } from "jscrypto/Word32Array";
import { None } from "./__python_types__";
import type { G1Element } from "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 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[] | string | G1Element | None, type?: BytesFromType): Bytes;
static SHA256(value: string | Bytes | Uint8Array): Bytes;
get length(): number;
at(i: number): number;
concat(b: Bytes): Bytes;
repeat(n: number): Bytes;
slice(start: number, length?: number): Bytes;
subarray(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;
toJSON(): string;
}
export declare function b(utf8Str: string, type?: "utf8" | "hex"): Bytes;
export declare function h(hexStr: string): Bytes;
export declare function list<T = unknown>(iterable: Iterable<T>): T[];
export declare function str(x: any): any;
export declare function repr(x: any): any;
export declare class Tuple<T1, T2> extends Array<any> {
constructor(...items: [T1, T2]);
toString(): string;
}
export declare function t<T1, T2>(v1: T1, v2: T2): Tuple<T1, T2>;
export declare function isTuple(v: unknown): v is Tuple<unknown, unknown>;
/**
* 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;
asUint8Array(): Uint8Array;
}
/**
* Python's style division.
* In javascript, `-8 / 5 === -1` while `-8 / 5 == -2` in Python
*/
export declare function division(a: bigint, b: bigint): bigint;
/**
* Python's style modulo.
* In javascript, `-8 % 5 === -3` while `-8 % 5 == 2` in Python
*/
export declare function modulo(a: bigint, b: bigint): bigint;
export declare function divmod(a: bigint, b: bigint): Tuple<bigint, bigint>;