@vecrea/oid4vc-prex
Version:
A TypeScript library for handling OpenID for Verifiable Credentials (OID4VC) Presentation Exchange operations
89 lines (88 loc) • 2.48 kB
TypeScript
import { z } from 'zod';
import { InputDescriptorId } from './InputDescriptorId';
import { JsonPath } from './JsonPath';
/**
* Zod schema for validating descriptor map values.
*
* This schema ensures that a descriptor map is an object with the following properties:
* - id: an InputDescriptorId
* - format: a string
* - path: a JSONPath
* - path_nested: an optional nested descriptor map
*
* @type {z.ZodType<DescriptorMapJSON>}
*
* @example
* // Valid usage
* descriptorMapSchema.parse({
* id: '123',
* format: 'json',
* path: '$.abc123',
* path_nested: {
* id: '456',
* format: 'json',
* path: '$.def456'
* }
* }); // Returns { id: '123', format: 'json', path: '$.abc123', path_nested: { id: '456', format: 'json', path: '$.def456' } }
*
* // Invalid usage (will throw ZodError)
* descriptorMapSchema.parse({
* id: '123',
* format: 'json',
* path: '$.abc123',
* path_nested: {
* id: '456',
* format: 'json',
* path: 'def456'
* }
* }); // Throws error: Invalid JSONPath
*
* @throws {z.ZodError} Throws a ZodError if the input fails validation
*/
export declare const descriptorMapSchema: z.ZodType<DescriptorMapJSON>;
/**
* Type of a descriptor map JSON object.
*/
export type DescriptorMapJSON = {
id: string;
format: string;
path: string;
path_nested?: DescriptorMapJSON;
};
/**
* Represents a descriptor map.
* A descriptor map is an object that describes the path to a JSON value.
*
* @class
*
* @param {InputDescriptorId} id The input descriptor ID
* @param {string} format The format of the JSON value
* @param {JsonPath} path The JSON path to the value
* @param {DescriptorMap} pathNested An optional nested descriptor map
*
*/
export declare class DescriptorMap {
id: InputDescriptorId;
format: string;
path: JsonPath;
pathNested?: DescriptorMap | undefined;
/**
* Constructor for DescriptorMap
* @param {InputDescriptorId} id
* @param {string} format
* @param {JsonPath} path
* @param {DescriptorMap} pathNested
*/
constructor(id: InputDescriptorId, format: string, path: JsonPath, pathNested?: DescriptorMap | undefined);
/**
* Converts JSON to DescriptorMap
* @param {DescriptorMapJSON} json
* @returns {DescriptorMap}
*/
static fromJSON(json: DescriptorMapJSON): DescriptorMap;
/**
* Converts DescriptorMap to JSON
* @returns {DescriptorMapJSON}
*/
toJSON(): DescriptorMapJSON;
}