/**
 * Shamir Secret Sharing - Type Definitions
 *
 * Provides strong type definitions for verified Shamir Secret Sharing implementation.
 * All types are designed to enforce mathematical constraints at the type level.
 *
 * @module security/crypto/shamir/types
 */
/**
 * Type guard for ShareIndex.
 */
export function isShareIndex(value) {
    return Number.isInteger(value) && value >= 1 && value <= 255;
}
/**
 * Type guard for GF256Element.
 */
export function isGF256Element(value) {
    return Number.isInteger(value) && value >= 0 && value <= 255;
}
/**
 * Create a ShareIndex from a number (validates range).
 * @throws Error if value is not in valid range [1, 255]
 */
export function createShareIndex(value) {
    if (!isShareIndex(value)) {
        throw new RangeError(`Share index must be in range [1, 255], got ${value}`);
    }
    return value;
}
/**
 * Create a GF256Element from a number (validates range).
 * @throws Error if value is not in valid range [0, 255]
 */
export function createGF256Element(value) {
    if (!isGF256Element(value)) {
        throw new RangeError(`GF(2^8) element must be in range [0, 255], got ${value}`);
    }
    return value;
}
/**
 * Validate ShamirParams.
 */
export function validateShamirParams(params) {
    const warnings = [];
    if (!Number.isInteger(params.threshold)) {
        return { valid: false, error: 'Threshold must be an integer' };
    }
    if (!Number.isInteger(params.totalShares)) {
        return { valid: false, error: 'Total shares must be an integer' };
    }
    if (!Number.isInteger(params.secretLength)) {
        return { valid: false, error: 'Secret length must be an integer' };
    }
    if (params.threshold < 1) {
        return { valid: false, error: 'Threshold must be at least 1' };
    }
    if (params.threshold > 255) {
        return { valid: false, error: 'Threshold cannot exceed 255' };
    }
    if (params.totalShares < params.threshold) {
        return { valid: false, error: 'Total shares must be >= threshold' };
    }
    if (params.totalShares > 255) {
        return { valid: false, error: 'Total shares cannot exceed 255' };
    }
    if (params.secretLength < 1) {
        return { valid: false, error: 'Secret length must be at least 1 byte' };
    }
    // Warnings for potentially insecure configurations
    if (params.threshold === 1) {
        warnings.push('Threshold of 1 provides no security - any single share reveals the secret');
    }
    if (params.threshold === params.totalShares) {
        warnings.push('Threshold equals total shares - no redundancy, all shares required');
    }
    if (params.threshold < 3 && params.totalShares > 3) {
        warnings.push('Low threshold relative to total shares may indicate weak security requirements');
    }
    return { valid: true, warnings: warnings.length > 0 ? warnings : undefined };
}
//# sourceMappingURL=types.js.map