import { Repository } from 'typeorm'; import { BaseVerificationToken, BaseUser } from '../entities'; import { SMSProvider } from '../interfaces/provider.interface'; import { StorageAdapter } from '../interfaces/storage-adapter.interface'; import { NAuthConfig } from '../interfaces/config.interface'; import { ClientInfoService } from './client-info.service'; import { InternalAuthAuditService as AuthAuditService } from './auth-audit.service'; import { NAuthLogger } from '../utils/nauth-logger'; import { HookRegistryService } from './hook-registry.service'; import { SendVerificationSMSDTO, SendVerificationSMSResponseDTO, VerifyPhoneWithCodeDTO, VerifyPhoneResponseDTO, ResendVerificationSMSDTO, ResendVerificationSMSResponseDTO } from '../dto/verify-phone.dto'; import { VerifyPhoneWithCodeBySubDTO } from '../dto/verify-phone-by-sub.dto'; /** * Phone Verification Service (Core) * * Database-agnostic phone verification workflow with provider-driven SMS delivery. * * WHY: Keeps core business logic independent of database and SMS vendors. Databases are * injected via repository tokens and SMS via an `SMSProvider` adapter so consumers * can plug in Postgres, MySQL, or any SMS provider without code changes. * * @example * ```typescript * // Send OTP * const tokenId = await phoneVerificationService.sendVerificationSMS('user-sub'); * * // Verify by sub * await phoneVerificationService.verifyPhoneWithCodeBySub('user-sub', '123456'); * * // Resend * await phoneVerificationService.resendVerificationSMS('user-sub'); * ``` */ export declare class PhoneVerificationService { private readonly verificationTokenRepo; private readonly userRepo; private readonly smsProvider; private readonly storageAdapter; private readonly config; private readonly clientInfoService; private readonly logger; private readonly hookRegistry; private readonly auditService?; constructor(verificationTokenRepo: Repository, userRepo: Repository, smsProvider: SMSProvider, storageAdapter: StorageAdapter, config: NAuthConfig, clientInfoService: ClientInfoService, logger: NAuthLogger, hookRegistry: HookRegistryService, auditService?: AuthAuditService | undefined); /** * Send verification SMS to user identified by `sub`. * Applies rate limits and resend delay, stores hashed token + OTP, and sends via SMS provider. * * @param dto - Request DTO containing sub and skipAlreadyVerifiedCheck * @returns Response DTO with verification token ID * @throws {NAuthException} RATE_LIMIT_SMS | NOT_FOUND | PHONE_REQUIRED | ALREADY_VERIFIED | RATE_LIMIT_RESEND */ sendVerificationSMS(dto: SendVerificationSMSDTO): Promise; /** * Verify phone by phone number and code. * Handles duplicate phone numbers by selecting the token whose user matches the phone provided. * * @param dto - Request DTO containing phone and code * @returns Response DTO with success message * @throws {NAuthException} VERIFICATION_CODE_INVALID | VERIFICATION_CODE_EXPIRED | VERIFICATION_TOO_MANY_ATTEMPTS */ verifyPhoneWithCode(dto: VerifyPhoneWithCodeDTO): Promise; /** * Verify phone by user sub and code. * * @param dto - Request DTO containing sub and code * @returns Response DTO with success message */ verifyPhoneWithCodeBySub(dto: VerifyPhoneWithCodeBySubDTO): Promise; /** * Resend verification SMS * Supports both sub and phone-based resend * * @param dto - Request DTO containing sub or phone * @returns Response DTO with verification token ID */ resendVerificationSMS(dto: ResendVerificationSMSDTO): Promise; /** * Resend verification SMS by user sub (private helper) * * @param sub - External user identifier * @returns New verification token id */ private resendVerificationSMSBySub; /** * Resend verification SMS by phone number (private helper) * * @param phone - Phone number * @returns New verification token id */ private resendVerificationSMSForPhone; /** * Generate N-digit OTP code (default 6) */ private generateCode; /** * Generate secure random token */ private generateToken; /** * Hash token with SHA-256 */ private hashToken; /** * Mask phone number for logging (preserves last 4 digits) * Respects config.security.maskSensitiveData setting. * @private */ private maskPhone; } //# sourceMappingURL=phone-verification.service.d.ts.map