import { Abi, FieldNode, TypeNode } from './abi/types.js'; import { BufReader, BufWriter } from './internal.js'; /** * BCS Encoder interface. */ export interface BCSEncoder { assert(val: T): void; decode(reader: BufReader, type: TypeNode | TypeNode[]): T; encode(writer: BufWriter, val: T, type: TypeNode | TypeNode[]): void; type: TypeNode | TypeNode[]; } /** * BCS Encoder initialisation params. */ export type BCSEncoderInitParams = Partial> & Omit, 'assert' | 'type'>; /** * Options for instantiating an instance of BCS. */ export interface BCSOpts { addAbiTypes: boolean; addPkgTypes: boolean; addPrimitives: boolean; } export interface BCSMini { decode(data: Uint8Array): T; encode(val: T): Uint8Array; } /** * BCS implementation for Aldea builtins and types as defined in an ABI. * * ## Usage * * Instantitate BCS with an ABI document. From then, any Jig or function/method * args can be encoded/decoded. Methods can be matched using the `($|_)` * convention, where `$` matches an instance method and `_` matches a static method. * ``` * const bcs = new BCS(abi) * * // Encoding Jig state * const encoded = bcs.encode('MyJig', values) * const decoded = bcs.decode('MyJig', encoded) * * // Encoding method args * const encoded = bcs.encode('MyJig$update', args) * const decoded = bcs.decode('MyJig$update', encoded) * ``` * * Optionally a BCS instance can be instantiated with support for serializing * and deserializing ABI documents and Package bundles. * * ``` * const bcs = new BCS({ addAbiTypes: true, addPkgTypes: true }) * const encodedAbi = bcs.encode('abi', abi) * const encodedPkg = bcs.encode('pkg', pkg) * ``` */ export declare class BCS { static pkg: BCSMini<[string[], Map]>; private abi?; private jigNames; private typeEncoders; constructor(abiOrOpts: Abi | Partial, options?: Partial); /** * Decodes the given data using the specified type encoder. */ decode(name: string, data: Uint8Array): any; /** * Encoders the given value(s) using the specified type encoder. */ encode(name: string, val: any, writer?: BufWriter): Uint8Array; /** * Returns the registered `BCSEncoder` for the given type name. */ getTypeEncoder(name: string): BCSEncoder; /** * Registers the given type encoder. */ registerType(name: string, encoder: BCSEncoderInitParams): void; /** * Registers the given array of FieldNode's as an object type encoder. */ registerObjectType(name: string, fields: FieldNode[]): void; /** * Registers the given array of TypeNode's as a tuple type encoder. * * The work tuple is used here to describe a fixed length list of variable * types. In terms of Aldea, this would apple to function/method arguments. */ registerTupleType(name: string, types: TypeNode[]): void; private decodeTypes; private decodeType; private encodeTypes; private encodeType; private collectJigFieldTypes; private collectMethodArgTypes; private registerPrimitiveTypes; private registerMagicTypes; private registerAbiTypes; private registerPkgTypes; } //# sourceMappingURL=bcs.d.ts.map