UNPKG

@anuragchvn-blip/mandatekit

Version:

Production-ready Web3 autopay SDK for crypto-based recurring payments using EIP-712 mandates

112 lines 4 kB
/** * Validation utilities for MandateKit SDK * Provides comprehensive validation for mandates and related data * @module utils/validation */ import type { Address } from 'viem'; import type { Mandate, SignedMandate, VerificationResult } from '../types/index.js'; /** * Validates a mandate structure for completeness and correctness * * @param mandate - Mandate to validate * @throws {ValidationError} If any field is invalid * * @example * ```typescript * try { * validateMandate(mandate); * console.log('Mandate is valid'); * } catch (error) { * console.error('Validation failed:', error.message); * } * ``` */ export declare function validateMandate(mandate: Mandate): void; /** * Validates a signed mandate including signature format * * @param signedMandate - Signed mandate to validate * @throws {ValidationError} If mandate or signature is invalid */ export declare function validateSignedMandate(signedMandate: SignedMandate): void; /** * Checks if a mandate is currently active based on timestamps * * @param mandate - Mandate to check * @param currentTime - Current unix timestamp (defaults to now) * @returns True if mandate is within valid time window */ export declare function isMandateActive(mandate: Mandate, currentTime?: number): boolean; /** * Validates that a mandate is active, throwing descriptive errors if not * * @param mandate - Mandate to validate * @param currentTime - Current unix timestamp (defaults to now) * @throws {MandateNotYetValidError} If before validAfter * @throws {ExpiredMandateError} If after validBefore */ export declare function validateMandateActive(mandate: Mandate, currentTime?: number): void; /** * Validates execution count against maxPayments limit * * @param mandate - Mandate with potential maxPayments limit * @param executionCount - Current number of executed payments * @throws {MaxPaymentsReachedError} If limit exceeded */ export declare function validateExecutionCount(mandate: Mandate, executionCount: number): void; /** * Performs comprehensive validation of a mandate for execution * Combines multiple validation checks * * @param mandate - Mandate to validate * @param executionCount - Current number of executed payments * @param lastExecutionTime - Timestamp of last execution (if any) * @param currentTime - Current unix timestamp (defaults to now) * @returns Verification result with detailed status * * @example * ```typescript * const result = verifyMandateForExecution( * mandate, * executionCount, * lastExecutionTime * ); * if (result.isValid && result.isExecutionDue) { * // Safe to execute payment * } * ``` */ export declare function verifyMandateForExecution(mandate: Mandate, executionCount: number, lastExecutionTime?: number, currentTime?: number): VerificationResult; /** * Checks if two addresses are equal (case-insensitive) * * @param address1 - First address * @param address2 - Second address * @returns True if addresses are equal */ export declare function addressesEqual(address1: Address, address2: Address): boolean; /** * Validates that an amount is sufficient for a payment * * @param available - Available balance * @param required - Required amount * @param tokenSymbol - Token symbol for error message * @throws {ValidationError} If balance is insufficient */ export declare function validateSufficientBalance(available: bigint, required: bigint, tokenSymbol?: string): void; /** * Sanitizes metadata string to prevent injection attacks * * @param metadata - Metadata string to sanitize * @returns Sanitized metadata */ export declare function sanitizeMetadata(metadata: string): string; /** * Parses amount string to bigint, handling various formats * * @param amount - Amount as string or bigint * @returns Parsed bigint amount * @throws {ValidationError} If amount cannot be parsed */ export declare function parseAmount(amount: string | bigint): bigint; //# sourceMappingURL=validation.d.ts.map