import { Effect, Either, FastCheck, Schema, SchemaAST } from "effect"; import * as CML from "./CML/index.js"; import { ParseError } from "effect/ParseResult"; /** * Data type representing Plutus data for encoding/decoding * * @category model * * @since 2.0.0 */ export type Data = Integer | ByteArray | List | Map | Constr; /** * List data type for Plutus Data * * @category model * * @since 2.0.0 */ export interface List { readonly _tag: "List"; readonly list: readonly T[]; } /** * Map data type for Plutus Data * * @category model * * @since 2.0.0 */ export interface Map = ReadonlyArray<{ k: Data; v: Data; }>> { readonly _tag: "Map"; readonly entries: Pairs; } /** * Constructor data type for Plutus Data * * @category model * * @since 2.0.0 */ export interface Constr { readonly _tag: "Constr"; readonly index: T; readonly fields: U; } /** * Integer data type for Plutus Data * * @category model * * @since 2.0.0 */ export interface Integer { readonly _tag: "Integer"; readonly integer: T; } /** * ByteArray data type for Plutus Data * * @category model * * @since 2.0.0 */ export interface ByteArray { readonly _tag: "ByteArray"; readonly bytearray: T; } /** * Schema for Integer data type * * @category schemas * * @since 2.0.0 */ export interface Integer$ extends Schema.Struct<{ _tag: Schema.tag<"Integer">; } & { integer: typeof Schema.BigIntFromSelf; }> { } /** * Schema for the Integer data type * * @category schemas * * @since 2.0.0 */ export declare const Integer: Integer$; /** * Schema for ByteArray data type * * @category schemas * * @since 2.0.0 */ export interface ByteArray$ extends Schema.Struct<{ _tag: Schema.tag<"ByteArray">; } & { bytearray: Schema.filter>; }> { } /** * Schema for the ByteArray data type * * @category schemas * * @since 2.0.0 */ export declare const ByteArray: ByteArray$; /** * Schema for List data type * * @category schemas * * @since 2.0.0 */ export interface List$ extends Schema.Struct<{ _tag: Schema.tag<"List">; } & { list: Schema.Array$>; }> { } /** * Schema for the List data type * * @category schemas * * @since 2.0.0 */ export declare const List: List$; /** * Filter to ensure uniqueness by first item in entries * * @category utilities * * @since 2.0.0 */ export declare const uniqueByFirst: (schema: Schema.Struct<{ k: Schema.Schema; v: Schema.Schema; }>) => Schema.filter; v: Schema.Schema; }>>>; /** * Schema for Map data type * * @category schemas * * @since 2.0.0 */ export interface Map$ extends Schema.Struct<{ _tag: Schema.tag<"Map">; } & { entries: Schema.refine; v: Schema.Schema; }>>>; }> { } /** * Schema for the Map data type * * @category schemas * * @since 2.0.0 */ export declare const Map: Map$; /** * Schema for Constr data type * * @category schemas * * @since 2.0.0 */ export interface Constr$ extends Schema.Struct<{ _tag: Schema.tag<"Constr">; } & { index: Schema.filter; fields: Schema.Array$>; }> { } /** * Schema for the Constr data type * * @category schemas * * @since 2.0.0 */ export declare const Constr: Constr$; /** * Combined schema for Data type * * @category schemas * * @since 2.0.0 */ export declare const Data: Schema.Schema; /** * Type guard to check if a value is a Data.Integer * * @category predicates * * @example * import { Data } from "@lucid-evolution/experimental"; * * const value = Data.mkByte("deadbeef"); * const isByte = Data.isByteArray(value); // true * * @since 2.0.0 */ export declare const isByteArray: (u: unknown, overrideOptions?: SchemaAST.ParseOptions | number) => u is { readonly _tag: "ByteArray"; readonly bytearray: string; }; /** * Type guard to check if a value is a Data.Integer * * @category predicates * * @example * import { Data } from "@lucid-evolution/experimental"; * * const value = Data.mkInt(42n); * const isInteger = Data.isInteger(value); // true * * @since 2.0.0 */ export declare const isInteger: (u: unknown, overrideOptions?: SchemaAST.ParseOptions | number) => u is { readonly integer: bigint; readonly _tag: "Integer"; }; /** * Type guard to check if a value is a Data.List * * @category predicates * * @example * import { Data } from "@lucid-evolution/experimental"; * * const value = Data.mkList([Data.mkInt(1n), Data.mkInt(2n)]); * const isList = Data.isList(value); // true * * @since 2.0.0 */ export declare const isList: (u: unknown, overrideOptions?: SchemaAST.ParseOptions | number) => u is { readonly _tag: "List"; readonly list: readonly Data[]; }; /** * Type guard to check if a value is a Data.Map * * @category predicates * * @example * import { Data } from "@lucid-evolution/experimental"; * * const value = Data.mkMap([ * { k: Data.mkByte("cafe01"), v: Data.mkInt(1n) }, * { k: Data.mkByte("cafe02"), v: Data.mkInt(2n) } * ]); * const isMap = Data.isMap(value); // true * * @since 2.0.0 */ export declare const isMap: (u: unknown, overrideOptions?: SchemaAST.ParseOptions | number) => u is { readonly entries: readonly { readonly k: Data; readonly v: Data; }[]; readonly _tag: "Map"; }; /** * Type guard to check if a value is a Data.Constr * * @category predicates * * @example * import { Data } from "@lucid-evolution/experimental"; * * const value = Data.mkConstr(0n, [Data.mkInt(1n), Data.mkInt(2n)]); * const isConstr = Data.isConstr(value); // true * * @since 2.0.0 */ export declare const isConstr: (u: unknown, overrideOptions?: SchemaAST.ParseOptions | number) => u is { readonly index: bigint; readonly _tag: "Constr"; readonly fields: readonly Data[]; }; /** * Converts TypeScript data into CBOR hex string * * @category encoding/decoding * * @example * import { Data, TSchema } from "@lucid-evolution/experimental" * * const Token = TSchema.Struct({ * policyId: TSchema.ByteArray, * assetName: TSchema.ByteArray, * amount: TSchema.Integer * }) * * const token = { * policyId: "deadbeef", * assetName: "cafe", * amount: 1000n * } * * // Convert to canonical CBOR * const cbor = Data.encodeCBOROrThrow(token, Token, { canonical: true }) * * @since 2.0.0 */ export declare const encodeCBOROrThrow: (input: unknown, schema?: Schema.Schema, options?: { canonical?: boolean; parseOptions?: SchemaAST.ParseOptions; }) => string; export declare const encodeCBOR: (input: unknown, schema?: Schema.Schema | undefined, options?: { canonical?: boolean; parseOptions?: SchemaAST.ParseOptions; } | undefined) => Effect.Effect; /** * Decodes a CBOR hex string to a TypeScript type * * @category encoding/decoding * * @example * import { TSchema , Data } from "@lucid-evolution/experimental"; * * const Token = TSchema.Struct({ * policyId: TSchema.ByteArray, * assetName: TSchema.ByteArray, * amount: TSchema.Integer * }) * * const cbor = "d8799f44deadbeef42cafe1903e8ff" * * // Decode from CBOR * const token = Data.decodeCBOROrThrow(cbor, Token) * // { policyId: "deadbeef", assetName: "cafe", amount: 1000n } * * // Decode without schema * const data = Data.decodeCBOROrThrow(cbor) * // { * // _tag: 'Constr', * // index: 0n, * // fields: [ * // { _tag: 'ByteArray', bytearray: 'deadbeef' }, * // { _tag: 'ByteArray', bytearray: 'cafe' }, * // { _tag: 'Integer', integer: 1000n } * // ] * // } * * @since 2.0.0 */ export declare function decodeCBOROrThrow(input: string): Data; export declare function decodeCBOROrThrow(input: string, schema: Schema.Schema): Source; export declare const decodeCBOR: (input: string, schema?: Schema.Schema | undefined) => Effect.Effect<{ readonly integer: bigint; readonly _tag: "Integer"; } | { readonly _tag: "ByteArray"; readonly bytearray: string; } | { readonly _tag: "List"; readonly list: readonly Data[]; } | { readonly entries: readonly { readonly k: Data; readonly v: Data; }[]; readonly _tag: "Map"; } | { readonly index: bigint; readonly _tag: "Constr"; readonly fields: readonly Data[]; } | Source, ParseError | CML.PlutusData.PlutusDataError, never>; /** * Resolves a CBOR hex string to a Plutus Data structure * * @category transformation * * @since 2.0.0 */ export declare const resolveCBOROrThrow: (input: string) => Data; export declare const resolveCBOR: (input: string) => Effect.Effect<{ readonly integer: bigint; readonly _tag: "Integer"; } | { readonly _tag: "ByteArray"; readonly bytearray: string; } | { readonly _tag: "List"; readonly list: readonly Data[]; } | { readonly entries: readonly { readonly k: Data; readonly v: Data; }[]; readonly _tag: "Map"; } | { readonly index: bigint; readonly _tag: "Constr"; readonly fields: readonly Data[]; }, CML.PlutusData.PlutusDataError, never>; /** * Decodes an unknown value from Plutus Data Constructor to a TypeScript type * * @throws {ParseError} If the input value does not match the schema * * @category encoding/decoding * * @example * import { Data, TSchema } from "@lucid-evolution/experimental"; * * const Token = TSchema.Struct({ * policyId: TSchema.ByteArray, * assetName: TSchema.ByteArray, * amount: TSchema.Integer * }); * * const plutusData = Data.mkConstr(0n, [ * Data.mkByte("deadbeef"), * Data.mkByte("cafe"), * Data.mkInt(1000n) * ]); * * const token = Data.decodeDataOrThrow(plutusData, Token); * // { policyId: "deadbeef", assetName: "cafe", amount: 1000n } * * @since 2.0.0 */ export declare const decodeDataOrThrow: (input: unknown, schema: Schema.Schema, options?: SchemaAST.ParseOptions) => Source; export declare const decodeData: (input: unknown, schema: Schema.Schema, options?: SchemaAST.ParseOptions | undefined) => Effect.Effect; /** * Safely decodes data using Either for error handling * * @category encoding/decoding * * @since 2.0.0 */ export declare const decodeDataEither: (input: unknown, schema: Schema.Schema, options?: SchemaAST.ParseOptions) => Either.Either; /** * Encodes a TypeScript value to Plutus Data Constructor * * @throws {ParseError} If the input value does not match the schema * * @category encoding/decoding * * @example * import { Data , TSchema } from "@lucid-evolution/experimental"; * * const token : unknown = { * policyId: "deadbeef", * assetName: "cafe", * amount: 1000n * }; * * const Token = TSchema.Struct({ * policyId: TSchema.ByteArray, * assetName: TSchema.ByteArray, * amount: TSchema.Integer * }); * * const data = Data.encodeDataOrThrow(token, Token); * // { index: 0n, fields: ["deadbeef", "cafe", 1000n] } * * @since 2.0.0 */ export declare const encodeDataOrThrow: (input: unknown, schema: Schema.Schema, options?: SchemaAST.ParseOptions) => Target; export declare const encodeData: (input: unknown, schema: Schema.Schema, options?: SchemaAST.ParseOptions | undefined) => Effect.Effect; /** * Safely encodes data using Either for error handling * * @category encoding/decoding * * @since 2.0.0 */ export declare const encodeDataEither: (input: unknown, schema: Schema.Schema, options?: SchemaAST.ParseOptions) => Either.Either; /** * Creates a Plutus Data List type from an array of Data elements * * @category constructors * * @example * import { Data } from "@lucid-evolution/experimental"; * * // Create a list with multiple elements of the same type * const integerList = Data.mkList([ * Data.mkInt(42n), * Data.mkInt(100n) * ]); * * // Create a list with a single element * const singleList = Data.mkList([Data.mkInt(42n)]); * * // Create a mixed list with different element types * const mixedList = Data.mkList([ * Data.mkInt(42n), * Data.mkByte("deadbeef") * ]); * * @since 2.0.0 */ export declare const mkList: (list: readonly T[]) => List; /** * Creates a Plutus Data Integer type from a bigint value * * @category constructors * * @example * import { Data } from "@lucid-evolution/experimental"; * * const myInteger = Data.mkInt(42n); * * @since 2.0.0 */ export declare const mkInt: (integer: T) => Integer; /** * Creates a Plutus Data ByteArray type from a hex string * * @category constructors * * @example * import { Data } from "@lucid-evolution/experimental"; * * const myByteArray = Data.mkByte("deadbeef"); * * @since 2.0.0 */ export declare const mkByte: (bytearray: T) => ByteArray; /** * Creates a Plutus Data Map type from an array of key-value tuples * * @category constructors * * @example * import { Data } from "@lucid-evolution/experimental"; * * const myMap = Data.mkMap([ * { k: Data.mkByte("cafe01"), v: Data.mkInt(42n) }, * { k: Data.mkByte("deadbeef"), v: Data.mkByte("cafe01") } * ]); * * @since 2.0.0 */ export declare const mkMap: >(value: Pairs) => Map; /** * Creates a Plutus Data Constr type (constructor) with the given index and fields * * @category constructors * * @example * import { Data } from "@lucid-evolution/experimental"; * * // Create a constructor for a custom data type (e.g., a "Mint" action with amount) * const mint = Data.mkConstr(0n, [Data.mkInt(5n)]); * * // Create a constructor with no fields (e.g., a "Burn" action) * const burn = Data.mkConstr(1n, []); * * @since 2.0.0 */ export declare const mkConstr: (index: T, fields: U) => Constr; /** * Converts a Data value to a JSON string * * @category transformation * * @example * import { Data } from "@lucid-evolution/experimental"; * * const data = Data.mkInt(42n); * const json = Data.toJSON(data); * // '{"_tag":"Integer","integer":"42n"}' * * @since 2.0.0 */ export declare const toJSON: (data: Data) => string; /** * Parses a JSON string to a Data value * * @category transformation * * @example * import { Data } from "@lucid-evolution/experimental"; * * @throws {Error} If the JSON string is invalid or does not match the expected format * * const json = '{"_tag":"Integer","integer":"42n"}'; * const data = Data.fromJSON(json); * // { _tag: 'Integer', integer: 42n } * * @since 2.0.0 */ export declare const fromJSONOrThrow: (json: string) => Data; /** * Compares two Data values for equality * * @category equality * * @example * import { Data } from "@lucid-evolution/experimental"; * * Data.isEqual(Data.mkInt(1n), Data.mkInt(1n)); // true * Data.isEqual(Data.mkInt(1n), Data.mkInt(2n)); // false * Data.isEqual(Data.mkByte("01"), Data.mkByte("01")); // true * Data.isEqual(Data.mkByte("cafe"), Data.mkByte("cafe01")); // false * Data.isEqual(Data.mkList([Data.mkInt(1n)]), Data.mkList([Data.mkInt(1n)])); // true * Data.isEqual(Data.mkList([Data.mkInt(1n)]), Data.mkList([Data.mkInt(2n)])); // false * Data.isEqual(Data.mkMap([{ k: Data.mkByte("deadbeef"), v: Data.mkInt(1n) }]), Data.mkMap([{ k: Data.mkByte("deadbeef"), v: Data.mkInt(1n) }])); // true * Data.isEqual(Data.mkMap([{ k: Data.mkByte("cafe"), v: Data.mkInt(1n) }]), Data.mkMap([{ k: Data.mkByte("deadbeef"), v: Data.mkInt(2n) }])); // false * Data.isEqual(Data.mkConstr(0n, [Data.mkInt(1n)]), Data.mkConstr(0n, [Data.mkInt(1n)])); // true * Data.isEqual(Data.mkConstr(0n, [Data.mkInt(1n)]), Data.mkConstr(1n, [Data.mkInt(2n)])); // false * * @since 2.0.0 */ export declare const isEqual: (a: Data, b: Data) => boolean; /** * Compares two Data values according to CBOR canonical ordering rules * * @category ordering * * @example * import { Data } from "@lucid-evolution/experimental"; * import assert from "assert" * * Data.compare(Data.mkInt(1n), Data.mkInt(2n)); // -1 * Data.compare(Data.mkInt(2n), Data.mkInt(2n)); // 0 * assert(Data.compare(Data.mkByte("cafe"), Data.mkByte("deadbeef")) === -1); // -1 * * @since 2.0.0 */ export declare const compare: (a: Data, b: Data) => number; /** * Creates an arbitrary that generates Data.Data values with controlled depth * * @category generators * * @example * import { Data } from "@lucid-evolution/experimental"; * import { FastCheck } from "effect" * * const data = Data.genData(3); * const sample = FastCheck.sample(data); * * @since 2.0.0 */ export declare const genData: (depth?: number) => FastCheck.Arbitrary; /** * Creates an arbitrary that generates Data.ByteArray values * * @category generators * * @since 2.0.0 */ export declare const genByteArray: () => FastCheck.Arbitrary; /** * Creates an arbitrary that generates Data.Integer values * * @category generators * * @since 2.0.0 */ export declare const genInteger: () => FastCheck.Arbitrary; /** * Creates an arbitrary that generates Data.List values * * @category generators * * @since 2.0.0 */ export declare const genList: (depth: number) => FastCheck.Arbitrary; /** * Creates an arbitrary that generates Data.Constr values * * @category generators * * @since 2.0.0 */ export declare const genConstr: (depth: number) => FastCheck.Arbitrary; /** * Creates an arbitrary that generates Data.Map values with unique keys * Following the Plutus distribution of key types: * - 60% ByteArray keys * - 30% Integer keys * - 10% Complex keys * * @category generators * * @example * import { Data } from "@lucid-evolution/experimental"; * import { FastCheck } from "effect" * * const mapArb = Data.genMap(2); * const sample = FastCheck.sample(mapArb); * * @since 2.0.0 */ export declare const genMap: (depth: number) => FastCheck.Arbitrary; /** * Sorts a Data value in canonical order * * @category ordering * * @example * import { Data } from "@lucid-evolution/experimental"; * * const data = Data.mkMap([ * { k: Data.mkByte("cafe"), v: Data.mkInt(2n) }, * { k: Data.mkByte("deadbeef"), v: Data.mkInt(1n) } * ]); * * const sortedData = Data.sort(data); * * @since 2.0.0 */ export declare const sort: (data: Data) => Data; //# sourceMappingURL=Data.d.ts.map