import { array } from "./schema/array.js"; import { tuple } from "./schema/tuple.js"; import { union } from "./schema/union.js"; import { type CBORTypedTag, tagged } from "./schema/tagged.js"; import { optional } from "./schema/optional.js"; import { field, map, numberField } from "./schema/map.js"; import { nested } from "./schema/nested.js"; import { literal } from "./schema/literal.js"; import type { CBORSchemaType, CBORSchemaValue, FieldDefinition } from "./schema/type.js"; import { lazy } from "./schema/lazy.js"; /** * Infers the TypeScript type from a CBOR schema, an alias of CBORSchemaValue * * @template T The schema type to infer from * @example * ```typescript * const cwtClaims = cs.map([ * cs.numberField(1, "iss", cs.string), * cs.numberField(4, "exp", cs.integer), * cs.numberField(7, "cti", cs.bytes), * ]); * * type CWT = valueOf; * ``` */ export type valueOf = CBORSchemaValue; /** * Main schema builder class containing all schema constructors and primitive types. * Prefer use of the shorthand alias `cs`. * * @example * ```typescript * // Using primitive schemas * const stringSchema = cs.string; * const numberSchema = cs.float; * * // Creating complex schemas * const Ec2KeyParametersSchema = cs.map([ * cs.numberField(1, "kty", cs.literal(2)), * cs.numberField(2, "kid", cs.optional(cs.bytes)), * cs.numberField(3, "alg", cs.optional(cs.literal(-7))), * cs.numberField( * 4, * "key_ops", * cs.optional(cs.array(cs.union([cs.literal(1), cs.literal(2)]))), * ), * cs.numberField(-1, "crv", cs.literal(1)), * cs.numberField(-2, "x", cs.bytes), * cs.numberField(-3, "y", cs.union([cs.bytes, cs.boolean])), * cs.numberField(-4, "d", cs.optional(cs.bytes)), * ]); * * // Encoding and decoding * const encoded = cs.toCBOR(Ec2KeyParametersSchema, { * kty: 2, * alg: -7, * crv: 1, * x: new Uint8Array([1, 2, 3]), * y: new Uint8Array([4, 5, 6]) * }); * const decoded = cs.fromCBOR(Ec2KeyParametersSchema, encoded); * ``` */ export declare class CBORSchema { static array: typeof array; static integer: CBORSchemaType; static bigint: CBORSchemaType; static string: CBORSchemaType; static boolean: CBORSchemaType; static float: CBORSchemaType; static bytes: CBORSchemaType>; static tuple: typeof tuple; static union: typeof union; static tagged: typeof tagged; static optional: typeof optional; static map: typeof map; static field: typeof field; static numberField: typeof numberField; static nested: typeof nested; static literal: typeof literal; static lazy: typeof lazy; /** * Decodes a CBOR byte array using the provided schema * * @template T The type to decode to * @param schema The schema to use for decoding * @param data The CBOR encoded data * @returns The decoded value * * @example * ```typescript * const data = new Uint8Array([101, 72, 101, 108, 108, 111]); // "Hello" in CBOR * const value = cs.fromCBOR(cs.string, data); * ``` */ static fromCBOR(schema: CBORSchemaType, data: Uint8Array | ArrayBuffer | DataView): T; /** * Encodes a value to CBOR using the provided schema * * @template T The type of the value to encode * @param schema The schema to use for encoding * @param value The value to encode * @returns CBOR encoded data as Uint8Array * * @example * ```typescript * const schema = cs.string; * const encoded = cs.toCBOR(schema, "Hello, CBOR!"); * ``` */ static toCBOR(schema: CBORSchemaType, value: T): Uint8Array; } /** * Main schema builder class containing all schema constructors and primitive types. * Use this to build complex CBOR schemas that can encode/decode TypeScript types. * * @example * ```typescript * // Using primitive schemas * const stringSchema = cs.string; * const numberSchema = cs.float; * * // Creating complex schemas * const Ec2KeyParametersSchema = cs.map([ * cs.numberField(1, "kty", cs.literal(2)), * cs.numberField(2, "kid", cs.optional(cs.bytes)), * cs.numberField(3, "alg", cs.optional(cs.literal(-7))), * cs.numberField( * 4, * "key_ops", * cs.optional(cs.array(cs.union([cs.literal(1), cs.literal(2)]))), * ), * cs.numberField(-1, "crv", cs.literal(1)), * cs.numberField(-2, "x", cs.bytes), * cs.numberField(-3, "y", cs.union([cs.bytes, cs.boolean])), * cs.numberField(-4, "d", cs.optional(cs.bytes)), * ]); * * // Encoding and decoding * const encoded = cs.toCBOR(Ec2KeyParametersSchema, { * kty: 2, * alg: -7, * crv: 1, * x: new Uint8Array([1, 2, 3]), * y: new Uint8Array([4, 5, 6]) * }); * const decoded = cs.fromCBOR(Ec2KeyParametersSchema, encoded); * ``` */ export declare const cs: typeof CBORSchema; export type { CBORTypedTag, FieldDefinition }; //# sourceMappingURL=cbor_schema.d.ts.map