/**
 * Validation utilities
 */
import { isValidPrivacyAddress, PRIVACY_ADDRESS_LENGTH, } from '../types/address';
/**
 * Check if string is a valid Ethereum address (20-byte 0x…).
 */
export function isEvmAddress(address) {
    if (typeof address !== 'string')
        return false;
    return /^0x[a-fA-F0-9]{40}$/.test(address.trim());
}
/**
 * Check if string is a valid MPK hex (32-byte 0x…).
 */
export function isMpkHex(mpk) {
    if (typeof mpk !== 'string')
        return false;
    return /^0x[a-fA-F0-9]{64}$/.test(mpk.trim());
}
/**
 * Assert that input is a valid 20-byte EVM address (0x + 40 hex chars).
 */
export function assertEvmAddress(input, message) {
    if (typeof input !== 'string')
        throw new Error(message ?? 'Address is required');
    const trimmed = input.trim();
    if (!/^0x[a-fA-F0-9]{40}$/.test(trimmed)) {
        throw new Error(message ?? 'Invalid Ethereum address format');
    }
}
/**
 * Assert that amount is a positive bigint.
 */
export function assertBigIntAmount(amount, message) {
    if (typeof amount !== 'bigint') {
        throw new Error(message ?? 'Amount must be a bigint');
    }
    if (amount <= 0n) {
        throw new Error(message ?? 'Amount must be greater than 0');
    }
}
/**
 * Check if string is a valid privacy address (96-byte hex: MPK + viewing public key)
 */
export function isPrivacyAddress(address) {
    return isValidPrivacyAddress(address);
}
/**
 * Assert that input is a valid privacy address (0x + 192 hex chars)
 *
 * @throws Error if address is invalid
 */
export function assertPrivacyAddress(address, message) {
    if (!isValidPrivacyAddress(address)) {
        throw new Error(message ?? `Invalid privacy address: expected ${PRIVACY_ADDRESS_LENGTH} character hex string`);
    }
}
/**
 * Validate master public key (MPK)
 *
 * @throws Error if MPK is invalid
 */
export function assertMpk(mpk) {
    if (typeof mpk === 'bigint') {
        if (mpk <= 0n) {
            throw new Error('Invalid MPK: must be greater than 0');
        }
        return;
    }
    // Hex format: 32 bytes = 64 hex chars + 0x = 66 chars
    if (typeof mpk === 'string') {
        if (!/^0x[a-fA-F0-9]{64}$/.test(mpk)) {
            throw new Error('Invalid MPK format: must be 32 bytes hex');
        }
        return;
    }
    throw new Error('MPK must be bigint or hex string');
}
//# sourceMappingURL=validation.js.map