@vecrea/oid4vc-prex
Version:
A TypeScript library for handling OpenID for Verifiable Credentials (OID4VC) Presentation Exchange operations
207 lines (206 loc) • 8.99 kB
TypeScript
import { z } from 'zod';
import { FieldConstraint, FieldConstraintJSON } from './FieldConstraint';
import { NonEmptySet } from './NonEmptySet';
/**
* Zod schema for a set of FieldConstraints.
* This schema ensures that a value is a non-empty set of FieldConstraints.
* It applies the following validations:
* - The value must be a non-empty set of FieldConstraints.
* @type {z.ZodNonEmptyArray}
* @example
* // Valid usage
* fieldsSchema.parse([{ path: ['$.a'], id: '123', name: 'name', purpose: 'purpose', filter: { type: 'string' }, optional: true, intent_to_retain: true }]); // Returns [{ path: ['$.a'], id: '123', name: 'name', purpose: 'purpose', filter: { type: 'string' }, optional: true, intent_to_retain: true }]
* // Invalid usage (will throw ZodError)
* fieldsSchema.parse([]); // Throws error: Invalid input
* @throws {z.ZodError} Throws a ZodError if the input fails validation
*/
export declare const fieldsSchema: z.ZodArray<z.ZodType<FieldConstraintJSON, any, FieldConstraintJSON>, "atleastone">;
/**
* Zod schema for a limit disclosure value.
* This schema ensures that a value is a valid limit disclosure value.
* It applies the following validations:
* - The value must be either 'required' or 'preferred'.
* @type {z.ZodEnum}
* @example
* // Valid usage
* limitDisclosureSchema.parse('required'); // Returns 'required'
* limitDisclosureSchema.parse('preferred'); // Returns 'preferred'
* // Invalid usage (will throw ZodError)
* limitDisclosureSchema.parse(''); // Throws error: Invalid enum member
* @throws {z.ZodError} Throws a ZodError if the input fails validation
*/
export declare const limitDisclosureSchema: z.ZodEnum<["required", "preferred"]>;
/**
* Zod schema for Constraints.
* This schema ensures that a value is a valid Constraints.
* It applies the following validations:
* - The value must be an object.
* - The object may have a fields property.
* - The fields property must be a non-empty set of FieldConstraints.
* - The object may have a limitDisclosure property.
* - The limitDisclosure property must be a valid limit disclosure value.
* @type {z.ZodObject}
* @example
* // Valid usage
* constraintsSchema.parse({ fields: [{ path: ['$.a'], id: '123', name: 'name', purpose: 'purpose', filter: { type: 'string' }, optional: true, intent_to_retain: true }], limitDisclosure: 'required' }); // Returns { fields: [{ path: ['$.a'], id: '123', name: 'name', purpose: 'purpose', filter: { type: 'string' }, optional: true, intent_to_retain: true }], limitDisclosure: 'required' }
* // Invalid usage (will throw ZodError)
* constraintsSchema.parse({ fields: [], limitDisclosure: 'required' }); // Throws error: Invalid input
*/
export declare const constraintsSchema: z.ZodType<ConstraintsJSON>;
/**
* Type of a set of FieldConstraint.
*/
export type FieldConstraintSet = NonEmptySet<FieldConstraint>;
/**
* Type of a set of FieldConstraintJSON.
*/
export type FieldConstraintJSONSet = FieldConstraintJSON[];
/**
* Type of a limit disclosure value.
*/
export type LimitDisclosureValue = z.infer<typeof limitDisclosureSchema>;
/**
* Type of a Constraints JSON object.
*/
export type ConstraintsJSON = {
fields?: FieldConstraintJSONSet;
limit_disclosure?: LimitDisclosureValue;
};
/**
* Interface for Constraints.
* This interface represents the constraints property of Input Descriptor
* @interface
*/
export interface Constraints {
readonly __type: 'Fields' | 'LimitDisclosure' | 'FieldsAndDisclosure';
toJSON(): ConstraintsJSON;
}
/**
* Namespace for Constraints.
* It contains classes and functions for Constraints.
* @namespace
*/
export declare namespace Constraints {
/**
* Represents a fields propertiy for the Constraints.
* It contains a set of FieldConstraint.
* @class
* @implements {Constraints}
* @param {FieldConstraintSet} fieldConstraints - The set of FieldConstraint.
* @example
* // Create a new Fields instance
* const fields = new Fields([new FieldConstraint('$.a'), new FieldConstraint('$.b')]);
*/
class Fields implements Constraints {
fieldConstraints: FieldConstraintSet;
readonly __type: "Fields";
/**
* Creates an instance of Fields.
* @param {FieldConstraintSet} fieldConstraints - The set of FieldConstraints.
* @throws {Error} Thrown when fieldConstraints is undefined or empty.
*/
constructor(fieldConstraints: FieldConstraintSet);
/**
* Creates an instance of Fields from a JSON object.
* @param {FieldConstraintJSONSet} fieldConstraints - The JSON object representing the Fields.
* @returns {Fields} A new Fields instance.
*/
static fromJSON(fieldsConstraints: FieldConstraintJSONSet): Fields;
/**
* Returns the JSON object representation of the Fields.
* @returns {FieldConstraintJSON[]} The JSON object representation of the Fields.
*/
toJSON(): ConstraintsJSON;
}
/**
* Represents a limit_disclosure propertiy for the Constraints.
* It contains a value that can be either 'required' or 'preferred'.
* @class
* @implements {Constraints}
* @param {LimitDisclosureValue} value - The value of the LimitDisclosure.
* @example
* // Create a new LimitDisclosure instance
* const limitDisclosure = LimitDisclosure.REQUIRED;
*/
class LimitDisclosure implements Constraints {
value: LimitDisclosureValue;
readonly __type: "LimitDisclosure";
/**
* The required limit disclosure value.
* @type {LimitDisclosure}
* @static
*/
static REQUIRED: LimitDisclosure;
/**
* The preferred limit disclosure value.
* @type {LimitDisclosure}
* @static
*/
static PREFERRED: LimitDisclosure;
/**
* Creates an instance of LimitDisclosure.
* @param {LimitDisclosureValue} value - The value of the LimitDisclosure.
* @private
*/
private constructor();
/**
* Returns The value of the LimitDisclosure.
* @returns {LimitDisclosureValue} The value of the LimitDisclosure.
*/
toJSON(): ConstraintsJSON;
/**
* Creates a LimitDisclosure instance from a string.
* @param {string} value - The string value of the LimitDisclosure.
* @returns {LimitDisclosure} A LimitDisclosure instance.
*/
static fromString(value: string): LimitDisclosure;
}
/**
* Represents a set of fields and a limit disclosure value for the Constraints.
* It contains a set of FieldConstraints and a limit disclosure value.
* @class
* @implements {Constraints}
* @param {FieldConstraintSet} fieldConstraints - The set of FieldConstraints.
* @param {LimitDisclosure} limitDisclosure - The limit disclosure value.
* @example
* // Create a new FieldsAndDisclosure instance
* const fieldsAndDisclosure = new FieldsAndDisclosure([new FieldConstraint('$.a'), new FieldConstraint('$.b')], LimitDisclosure.REQUIRED);
*/
class FieldsAndDisclosure implements Constraints {
fieldConstraints: FieldConstraintSet;
limitDisclosure: LimitDisclosure;
readonly __type: "FieldsAndDisclosure";
/**
* Creates an instance of FieldsAndDisclosure.
* @param {FieldConstraintSet} fieldConstraints - The set of FieldConstraints.
* @param {LimitDisclosure} limitDisclosure - The limit disclosure value.
* @throws {Error} Thrown when fieldConstraints is undefined or empty.
*/
constructor(fieldConstraints: FieldConstraintSet, limitDisclosure: LimitDisclosure);
/**
* Returns The value of the LimitDisclosure.
* @returns {LimitDisclosureValue} The value of the LimitDisclosure.
*/
toJSON(): ConstraintsJSON;
}
/**
* Returns the FieldConstraints of the Constraints.
* @param {Constraints} instance - The Constraints instance.
* @returns {FieldConstraint[]} The FieldConstraints of the Constraints.
*/
const fields: (instance: Constraints) => FieldConstraint[];
/**
* Returns the LimitDisclosure of the Constraints.
* @param {Constraints} instance - The Constraints instance.
* @returns {LimitDisclosure} The LimitDisclosure of the Constraints.
*/
const limitDisclosure: (instance: Constraints) => LimitDisclosure | undefined;
/**
* Returns a Constraints instance.
* @param {FieldConstraintJSON[]} fs - An array of FieldConstraint instance.
* @param {LimitDisclosure} limitDisclosure - The LimitDisclosure instance.
* @returns {Constraints} A Constraints instance.
*/
const of: (fs?: FieldConstraint[], limitDisclosure?: LimitDisclosure) => Constraints | undefined;
const fromJSON: (json: ConstraintsJSON) => Constraints;
}