export { UplcRuntimeError } from "./cek/index.js"; export { makeBasicUplcLogger } from "./logging/index.js"; export type ArgSizesCost = { calcCost: (argSizes: bigint[]) => bigint; }; export type ArgSizesCostClass = (params: CostModelParamsProxy) => ArgSizesCost; export type BuiltinCallback = (args: CekValue[], ctx: BuiltinContext) => CekValue; export type Builtin = BuiltinCostModel & { forceCount: number; nArgs: number; call: BuiltinCallback; }; export type BuiltinContext = { print: (message: string) => void; }; export type BuiltinCostModel = { name: string; cpuModel: ArgSizesCostClass; memModel: ArgSizesCostClass; }; /** * So we can later add things like env function name, function values */ export type CallSiteInfo = { site?: Site; functionName?: string; arguments?: CekValue[]; }; export type CekContext = BuiltinContext & { cost: CostTracker; getBuiltin: (id: number) => (undefined | Builtin); popLastMessage: () => string | undefined; print: (message: string, site?: Site | undefined) => void; }; export type CekFrame = { reduce: (value: CekValue, ctx: CekContext) => CekStateChange; }; /** * Return value is optional and can be omitted if the UplcValue doesn't suffice to contain it (eg. lambda functions) */ export type CekResult = { result: Either<{ error: string; callSites: CallSiteInfo[]; }, string | UplcValue>; cost: Cost; logs: { message: string; site?: Site; }[]; breakdown: CostBreakdown; }; export type CekStack = { values: CekValue[]; callSites: CallSiteInfo[]; }; export type CekState = { computing: { term: CekTerm; stack: CekStack; }; } | { reducing: CekValue; } | { error: { message: string; stack: CekStack; }; }; export type CekStateChange = { state: CekState; frame?: CekFrame; }; export type CekTerm = { site: Site | undefined; compute(stack: CekStack, ctx: CekContext): CekStateChange; toString(): string; }; /** * Generalized UplcValue * The optional name is used for debugging */ export type CekValue = { name?: string; } & ({ value: UplcValue; } | { delay: { term: CekTerm; stack: CekStack; }; } | { lambda: { term: CekTerm; argName?: string; stack: CekStack; }; } | { builtin: { id: number; name: string; forceCount: number; args: CekValue[]; }; }); export type Cost = { cpu: bigint; mem: bigint; }; export type CostBreakdown = { [name: string]: (Cost & { count: number; }); }; export type CostModel = { builtinTerm: Cost; callTerm: Cost; constTerm: Cost; delayTerm: Cost; forceTerm: Cost; lambdaTerm: Cost; startupTerm: Cost; varTerm: Cost; constrTerm: Cost; caseTerm: Cost; builtins: Record Cost>; }; export type CostModelParamsProxy = { get: (key: number, def?: bigint | undefined) => bigint; }; export type CostTracker = Cost & { costModel: CostModel; breakdown: CostBreakdown; incrBuiltinCost(): void; incrCallCost(): void; incrConstCost(): void; incrDelayCost(): void; incrForceCost(): void; incrLambdaCost(): void; incrStartupCost(): void; incrVarCost(): void; incrArgSizesCost(name: string, argSizes: bigint[]): void; }; export type FlatReader = { readBool: () => boolean; readBuiltinId: () => number; readBytes: () => number[]; readInt: () => bigint; readTag: () => number; readLinkedList: (elemSize: number) => number[]; readValue: () => UplcValue; readExpr: () => UplcTerm; }; export type FlatWriter = { writeBool: (b: boolean) => void; writeBytes: (bytes: number[]) => void; writeInt: (x: bigint) => void; writeList: (items: { toFlat: (w: FlatWriter) => void; }[]) => void; writeTermTag: (tag: number) => void; writeTypeBits: (typeBits: string) => void; writeBuiltinId: (id: number) => void; finalize: () => number[]; }; /** * Interface for Plutus-core data classes (not the same as Plutus-core value classes!) */ export type UplcData = ByteArrayData | ConstrData | IntData | ListData | MapData; export type CommonUplcDataProps = { memSize: number; isEqual: (other: UplcData) => boolean; toCbor: () => number[]; toSchemaJson: () => string; toString: () => string; rawData?: any; dataPath?: string; }; export type ByteArrayData = CommonUplcDataProps & { kind: "bytes"; bytes: number[]; toHex: () => string; }; export type ConstrData = CommonUplcDataProps & { kind: "constr"; tag: number; fields: UplcData[]; length: number; expectFields: (n: number) => ConstrData; expectTag: (tag: number, msg?: string) => ConstrData; }; export type IntData = CommonUplcDataProps & { kind: "int"; value: bigint; }; export type ListData = CommonUplcDataProps & { kind: "list"; items: UplcData[]; length: number; list: UplcData[]; }; export type MapData = CommonUplcDataProps & { kind: "map"; items: [UplcData, UplcData][]; length: number; list: [UplcData, UplcData][]; }; /** * Gathers log messages produced by a Helios program * Note: logError is intended for messages that are passed to console.error() or equivalent, not for the Error messages that are simply part of thrown errors */ export type UplcLogger = { logPrint: (message: string, site?: Site | undefined) => void; logError?: (message: string, stack?: Site | undefined) => void; lastMessage: string; logTrace?: (message: string, site?: Site | undefined) => void; flush?: () => void; reset?: (reason: "build" | "validate") => void; }; export type BasicUplcLogger = UplcLogger & { lastMessage: string; }; export type UplcProgram = UplcProgramV1 | UplcProgramV2 | UplcProgramV3; export type UplcVersion = "1.0.0" | "1.1.0"; export type PlutusVersion = "PlutusScriptV1" | "PlutusScriptV2" | "PlutusScriptV3"; export type PlutusVersionTag = 1 | 2 | 3; /** * The optional ir property can be lazy because it is only used for debugging and might require an expensive formatting operation */ export type UplcProgramV1Options = { alt?: UplcProgramV1; ir?: (() => string) | string; sourceMap?: UplcSourceMapJsonSafe; }; /** * The optional ir property can be lazy because it is only used for debugging and might require an expensive formatting operation */ export type UplcProgramV2Options = { alt?: UplcProgramV2; ir?: (() => string) | string; sourceMap?: UplcSourceMapJsonSafe; }; /** * The optional ir property can be lazy because it is only used for debugging and might require an expensive formatting operation */ export type UplcProgramV3Options = { alt?: UplcProgramV3; ir?: (() => string) | string; sourceMap?: UplcSourceMapJsonSafe; }; export type CommonUplcProgramProps = { root: UplcTerm; ir?: string; eval(args: UplcValue[] | undefined, options?: { logOptions?: UplcLogger; costModelParams?: number[]; }): CekResult; hash(): number[]; toCbor(): number[]; toFlat(): number[]; toString(): string; }; export type UplcProgramV1 = CommonUplcProgramProps & { plutusVersion: "PlutusScriptV1"; plutusVersionTag: 1; uplcVersion: "1.0.0"; alt?: UplcProgramV1; apply: (args: UplcValue[]) => UplcProgramV1; withAlt: (alt: UplcProgramV1) => UplcProgramV1; }; export type UplcProgramV2 = CommonUplcProgramProps & { plutusVersion: "PlutusScriptV2"; plutusVersionTag: 2; uplcVersion: "1.0.0"; alt?: UplcProgramV2; apply: (args: UplcValue[]) => UplcProgramV2; withAlt: (alt: UplcProgramV2) => UplcProgramV2; }; export type UplcProgramV3 = CommonUplcProgramProps & { plutusVersion: "PlutusScriptV3"; plutusVersionTag: 3; uplcVersion: "1.1.0"; alt?: UplcProgramV3; apply: (args: UplcValue[]) => UplcProgramV3; withAlt: (alt: UplcProgramV3) => UplcProgramV3; }; export type UplcSourceMapJsonSafe = { sourceNames: string[]; indices: string; variableNames?: string; termDescriptions?: string; }; export type UplcSourceMapProps = { sourceNames: string[]; indices: number[]; variableNames?: [number, string][]; termDescriptions?: [number, string][]; }; export type UplcSourceMap = { /** * Eg. file names or helios header names */ sourceNames: string[]; /** * Tuples of 4 indices * - First index in each tuple is the uplc term 'preorder' index * - Second index in each tuple is the source index (i.e. index in `this.sourceNames`) * - Third index in each tuple is the line number (0-based) * - Fourth index in each tuple is the column number (0-based) */ indices: number[]; /** * Tuple of uplc lambda term index and variable name */ variableNames: [number, string][]; /** * Tuple of uplc term index and description string */ termDescriptions: [number, string][]; apply: (root: UplcTerm) => void; toJsonSafe: () => UplcSourceMapJsonSafe; }; export type CommonUplcTermProps = CekTerm & { toFlat: (writer: FlatWriter) => void; children: UplcTerm[]; }; export type UplcTerm = (UplcBuiltin | UplcCall | UplcConst | UplcDelay | UplcError | UplcForce | UplcLambda | UplcVar); export type UplcBuiltin = CommonUplcTermProps & { kind: "builtin"; id: number; }; export type UplcCall = CommonUplcTermProps & { kind: "call"; fn: UplcTerm; arg: UplcTerm; }; export type UplcConst = CommonUplcTermProps & { kind: "const"; flatSize: number; serializableTerm: UplcTerm; value: UplcValue; }; export type UplcDelay = CommonUplcTermProps & { kind: "delay"; arg: UplcTerm; }; export type UplcError = CommonUplcTermProps & { kind: "error"; }; export type UplcForce = CommonUplcTermProps & { kind: "force"; arg: UplcTerm; }; export type UplcLambda = CommonUplcTermProps & { kind: "lambda"; expr: UplcTerm; argName?: string; }; export type UplcVar = CommonUplcTermProps & { kind: "var"; index: number; name?: string; }; export type UplcType = { typeBits: string; isData(): boolean; isDataPair(): boolean; isEqual(other: UplcType): boolean; toString(): string; }; /** * UplcValue instances are passed around by Uplc terms. * - memSize: size in words (8 bytes, 64 bits) occupied during on-chain evaluation * - flatSize: size taken up in serialized Uplc program (number of bits) * - typeBits: each serialized value is preceded by some typeBits * - toFlat: serialize as flat format bits (without typeBits) */ export type CommonUplcValueProps = { memSize: number; flatSize: number; type: UplcType; isEqual: (other: UplcValue) => boolean; toFlat: (writer: FlatWriter) => void; toString: () => string; }; export type UplcValue = (UplcInt | UplcByteArray | UplcString | UplcUnit | UplcBool | UplcList | UplcPair | UplcDataValue | Bls12_381_G1_element | Bls12_381_G2_element | Bls12_381_MlResult); export type UplcInt = CommonUplcValueProps & { kind: "int"; value: bigint; signed: boolean; toFlatUnsigned: (w: FlatWriter) => void; toSigned: () => UplcInt; toUnsigned: () => UplcInt; }; export type UplcByteArray = CommonUplcValueProps & { kind: "bytes"; bytes: number[]; }; export type UplcString = CommonUplcValueProps & { kind: "string"; value: string; string: string; }; export type UplcUnit = CommonUplcValueProps & { kind: "unit"; }; export type UplcBool = CommonUplcValueProps & { kind: "bool"; value: boolean; bool: boolean; toUplcData: () => ConstrData; }; export type UplcList = CommonUplcValueProps & { kind: "list"; itemType: UplcType; items: UplcValue[]; length: number; isDataList: () => boolean; isDataMap: () => boolean; }; export type UplcPair = CommonUplcValueProps & { kind: "pair"; first: UplcValue; second: UplcValue; }; export type UplcDataValue = CommonUplcValueProps & { kind: "data"; value: UplcData; }; export type Bls12_381_G1_element = CommonUplcValueProps & { kind: "bls12_381_G1_element"; point: Point3; compress: () => number[]; }; export type Bls12_381_G2_element = CommonUplcValueProps & { kind: "bls12_381_G2_element"; point: Point3<[bigint, bigint]>; compress: () => number[]; }; export type Bls12_381_MlResult = CommonUplcValueProps & { kind: "bls12_381_mlresult"; element: FieldElement12; }; import type { Site } from "@helios-lang/compiler-utils"; import type { Either } from "@helios-lang/type-utils"; import type { Point3 } from "@helios-lang/crypto"; import type { FieldElement12 } from "@helios-lang/crypto"; export { builtinsV1, builtinsV1Map, builtinsV2, builtinsV2Map, builtinsV3, builtinsV3Map } from "./builtins/index.js"; export { decodeCost, encodeCost, DEFAULT_COST_MODEL_PARAMS_V1, DEFAULT_COST_MODEL_PARAMS_V2, DEFAULT_COST_MODEL_PARAMS_V3 } from "./costmodel/index.js"; export { assertByteArrayData, assertConstrData, assertIntData, assertListData, assertMapData, expectByteArrayData, expectConstrData, expectIntData, expectListData, expectMapData, makeByteArrayData, makeConstrData, makeIntData, makeListData, makeMapData, uplcDataToBool, boolToUplcData, unwrapUplcDataOption, wrapUplcDataOption, uplcDataToReal, realToUplcData, decodeUplcData } from "./data/index.js"; export { makeFlatReader, makeFlatWriter } from "./flat/index.js"; export { decodeUplcProgramV1FromCbor, decodeUplcProgramV1FromFlat, decodeUplcProgramV2FromCbor, decodeUplcProgramV2FromFlat, decodeUplcProgramV3FromCbor, decodeUplcProgramV3FromFlat, decodeUplcProgramV2OrV3FromCbor, deserializeUplcSourceMap, encodeFullUplcProgram, isUplcVersion, makeUplcProgramV1, makeUplcProgramV2, makeUplcProgramV3, makeUplcSourceMap, restoreUplcProgram } from "./program/index.js"; export { makeUplcBuiltin, makeUplcCall, makeUplcConst, makeUplcDelay, makeUplcError, makeUplcForce, makeUplcLambda, makeUplcVar } from "./terms/index.js"; export { makeBls12_381_G1_element, makeBls12_381_G2_element, makeBls12_381_MlResult, makeUplcBool, makeUplcByteArray, makeUplcDataValue, makeUplcInt, makeUplcList, makeUplcPair, makeUplcString, makeListType, makePairType, makeUplcType, BLS12_381_G1_ELEMENT_TYPE, BLS12_381_G2_ELEMENT_TYPE, BLS12_381_ML_RESULT_TYPE, BOOL_TYPE, BYTE_ARRAY_TYPE, DATA_PAIR_TYPE, DATA_TYPE, INT_TYPE, STRING_TYPE, UNIT_TYPE, UNIT_VALUE } from "./values/index.js"; //# sourceMappingURL=index.d.ts.map