/**
 * Zero-Knowledge Proof Type Definitions
 *
 * Core type definitions for the ZKP system including proofs, verification results,
 * circuit definitions, and commitment schemes.
 *
 * This module follows the Vorion type definition patterns and integrates
 * with the existing security infrastructure.
 *
 * @packageDocumentation
 */
import { z } from 'zod';
// =============================================================================
// CIRCUIT TYPES
// =============================================================================
/**
 * Supported ZK circuit types
 */
export const ZKCircuitType = {
    /** Age verification without revealing date of birth */
    AGE_VERIFICATION: 'age_verification',
    /** Prove a value is within a range without revealing the value */
    RANGE_PROOF: 'range_proof',
    /** Prove membership in a set without revealing which element */
    SET_MEMBERSHIP: 'set_membership',
    /** Prove possession of a valid credential without revealing it */
    CREDENTIAL_VERIFICATION: 'credential_verification',
    /** Custom circuit for extensibility */
    CUSTOM: 'custom',
};
export const zkCircuitTypeSchema = z.nativeEnum(ZKCircuitType);
export const circuitMetadataSchema = z.object({
    type: zkCircuitTypeSchema,
    name: z.string().min(1),
    description: z.string(),
    version: z.string().regex(/^\d+\.\d+\.\d+$/),
    publicInputs: z.array(z.string()),
    privateInputs: z.array(z.string()),
    verificationKeyHash: z.string().optional(),
    registeredAt: z.coerce.date(),
});
export const zkProofSchema = z.object({
    proof: z.instanceof(Uint8Array),
    publicInputs: z.array(z.string()),
    circuit: z.string().min(1),
    timestamp: z.coerce.date(),
    expiresAt: z.coerce.date().optional(),
    metadata: z.record(z.unknown()).optional(),
    version: z.string().optional(),
    proofId: z.string().uuid().optional(),
});
export const serializedZKProofSchema = z.object({
    proof: z.string().min(1),
    publicInputs: z.array(z.string()),
    circuit: z.string().min(1),
    timestamp: z.string().datetime(),
    expiresAt: z.string().datetime().optional(),
    metadata: z.record(z.unknown()).optional(),
    version: z.string().optional(),
    proofId: z.string().uuid().optional(),
});
export const verificationResultSchema = z.object({
    valid: z.boolean(),
    circuit: z.string().min(1),
    verifiedAt: z.coerce.date(),
    publicInputs: z.array(z.string()),
    error: z.string().optional(),
    errorCode: z.string().optional(),
    verificationTimeMs: z.number().nonnegative().optional(),
    fromCache: z.boolean().optional(),
    cacheExpiresAt: z.coerce.date().optional(),
});
/**
 * Verification error codes for programmatic handling
 */
export const VerificationErrorCode = {
    /** Proof structure is invalid */
    INVALID_PROOF_FORMAT: 'INVALID_PROOF_FORMAT',
    /** Circuit not found or not registered */
    UNKNOWN_CIRCUIT: 'UNKNOWN_CIRCUIT',
    /** Proof has expired */
    PROOF_EXPIRED: 'PROOF_EXPIRED',
    /** Cryptographic verification failed */
    VERIFICATION_FAILED: 'VERIFICATION_FAILED',
    /** Public inputs don't match expected format */
    INVALID_PUBLIC_INPUTS: 'INVALID_PUBLIC_INPUTS',
    /** Verification key not found */
    MISSING_VERIFICATION_KEY: 'MISSING_VERIFICATION_KEY',
    /** Internal verification error */
    INTERNAL_ERROR: 'INTERNAL_ERROR',
};
export const batchVerificationResultSchema = z.object({
    allValid: z.boolean(),
    totalProofs: z.number().int().nonnegative(),
    validProofs: z.number().int().nonnegative(),
    results: z.array(verificationResultSchema),
    totalTimeMs: z.number().nonnegative(),
    completedAt: z.coerce.date(),
});
// =============================================================================
// COMMITMENT TYPES
// =============================================================================
/**
 * Commitment scheme types
 */
export const CommitmentScheme = {
    /** Pedersen commitment (additively homomorphic) */
    PEDERSEN: 'pedersen',
    /** Merkle tree commitment (for set membership) */
    MERKLE: 'merkle',
    /** Cryptographic accumulator (for dynamic sets) */
    ACCUMULATOR: 'accumulator',
    /** Hash commitment (simple binding) */
    HASH: 'hash',
};
export const commitmentSchemeSchema = z.nativeEnum(CommitmentScheme);
export const commitmentSchema = z.object({
    scheme: commitmentSchemeSchema,
    value: z.string().min(1),
    blindingFactor: z.string().optional(),
    createdAt: z.coerce.date(),
    parameters: z.record(z.unknown()).optional(),
});
export const merkleProofSchema = z.object({
    leaf: z.string().min(1),
    root: z.string().min(1),
    siblings: z.array(z.string()),
    pathIndices: z.array(z.number().int().min(0).max(1)),
    leafIndex: z.number().int().nonnegative(),
});
export const pedersenCommitmentSchema = z.object({
    commitment: z.string().min(1),
    generatorG: z.string().min(1),
    generatorH: z.string().min(1),
    value: z.string().optional(),
    blindingFactor: z.string().optional(),
});
export const zkCredentialSchema = z.object({
    id: z.string().min(1),
    issuer: z.string().min(1),
    subject: z.string().min(1),
    type: z.string().min(1),
    claims: z.record(z.unknown()),
    issuedAt: z.coerce.date(),
    expiresAt: z.coerce.date().optional(),
    signature: z.string().min(1),
    revocationCommitment: z.string().optional(),
});
export const selectiveDisclosureRequestSchema = z.object({
    proveExistence: z.array(z.string()),
    reveal: z.array(z.string()),
    predicates: z.array(z.lazy(() => predicateProofSchema)),
});
export const predicateProofSchema = z.object({
    claim: z.string().min(1),
    operator: z.enum(['gt', 'gte', 'lt', 'lte', 'eq', 'neq', 'in', 'not_in']),
    value: z.unknown(),
});
/**
 * Default ZK prover configuration
 */
export const DEFAULT_ZK_PROVER_CONFIG = {
    defaultProofTTL: 3600000, // 1 hour
    proofGenerationTimeout: 30000, // 30 seconds
    includeMetadata: true,
};
export const zkProverConfigSchema = z.object({
    defaultProofTTL: z.number().int().positive().default(DEFAULT_ZK_PROVER_CONFIG.defaultProofTTL),
    proofGenerationTimeout: z.number().int().positive().default(DEFAULT_ZK_PROVER_CONFIG.proofGenerationTimeout),
    includeMetadata: z.boolean().default(DEFAULT_ZK_PROVER_CONFIG.includeMetadata),
    circuitRegistryPath: z.string().optional(),
});
/**
 * Default ZK verifier configuration
 */
export const DEFAULT_ZK_VERIFIER_CONFIG = {
    enableCaching: true,
    cacheTTL: 300000, // 5 minutes
    maxCacheSize: 10000,
    rejectExpiredProofs: true,
    clockSkewTolerance: 5000, // 5 seconds
};
export const zkVerifierConfigSchema = z.object({
    enableCaching: z.boolean().default(DEFAULT_ZK_VERIFIER_CONFIG.enableCaching),
    cacheTTL: z.number().int().positive().default(DEFAULT_ZK_VERIFIER_CONFIG.cacheTTL),
    maxCacheSize: z.number().int().positive().default(DEFAULT_ZK_VERIFIER_CONFIG.maxCacheSize),
    rejectExpiredProofs: z.boolean().default(DEFAULT_ZK_VERIFIER_CONFIG.rejectExpiredProofs),
    clockSkewTolerance: z.number().int().nonnegative().default(DEFAULT_ZK_VERIFIER_CONFIG.clockSkewTolerance),
});
// =============================================================================
// COMPLIANCE TYPES
// =============================================================================
/**
 * Compliance verification type
 */
export const ComplianceVerificationType = {
    /** Know Your Customer verification */
    KYC: 'kyc',
    /** Anti-Money Laundering screening */
    AML: 'aml',
    /** GDPR data subject verification */
    GDPR: 'gdpr',
    /** PCI-DSS cardholder verification */
    PCI_DSS: 'pci_dss',
    /** SOC 2 access verification */
    SOC2: 'soc2',
    /** Custom compliance check */
    CUSTOM: 'custom',
};
export const complianceVerificationTypeSchema = z.nativeEnum(ComplianceVerificationType);
export const complianceProofRequestSchema = z.object({
    verificationType: complianceVerificationTypeSchema,
    requiredProofs: z.array(z.string()),
    constraints: z.record(z.unknown()).optional(),
    requestedAt: z.coerce.date(),
    expiresAt: z.coerce.date().optional(),
    nonce: z.string().min(1),
});
export const complianceVerificationResultSchema = z.object({
    verificationType: complianceVerificationTypeSchema,
    compliant: z.boolean(),
    proofResults: z.array(verificationResultSchema),
    verifiedAt: z.coerce.date(),
    validUntil: z.coerce.date().optional(),
    attestation: z.string().optional(),
});
export const trustedSetupParamsSchema = z.object({
    circuitId: z.string().min(1),
    participantsRequired: z.number().int().positive(),
    deadline: z.coerce.date(),
    phase: z.enum(['contribution', 'verification', 'complete']),
    transcriptHash: z.string().optional(),
});
export const provingKeySchema = z.object({
    keyId: z.string().min(1),
    circuitId: z.string().min(1),
    keyData: z.instanceof(Uint8Array),
    version: z.string(),
    hash: z.string().min(1),
    generatedAt: z.coerce.date(),
});
export const verificationKeySchema = z.object({
    keyId: z.string().min(1),
    circuitId: z.string().min(1),
    keyData: z.instanceof(Uint8Array),
    version: z.string(),
    hash: z.string().min(1),
    generatedAt: z.coerce.date(),
});
export const zkProofPolicyConditionSchema = z.object({
    circuit: zkCircuitTypeSchema,
    publicInputsPattern: z.record(z.unknown()).optional(),
    maxProofAge: z.number().int().positive().optional(),
    allowCachedVerification: z.boolean().optional(),
    complianceType: complianceVerificationTypeSchema.optional(),
});
export const sessionProofCacheSchema = z.object({
    sessionId: z.string().min(1),
    proofs: z.map(z.string(), zkProofSchema),
    verificationResults: z.map(z.string(), verificationResultSchema),
    createdAt: z.coerce.date(),
    expiresAt: z.coerce.date(),
});
//# sourceMappingURL=types.js.map