import { Injectable } from "@nestjs/common"; import { hash, verify } from "@node-rs/argon2"; @Injectable() export class HashingService { async hashEmail(email: string): Promise { const normalizedEmail = email.toLowerCase().trim(); return this.hashSha256(normalizedEmail); } async hashIp(ip: string): Promise { return this.hashSha256(ip); } async hashSha256(text: string): Promise { const data = new TextEncoder().encode(text); const hashBuffer = await crypto.subtle.digest("SHA-256", data); return Array.from(new Uint8Array(hashBuffer)) .map((b) => b.toString(16).padStart(2, "0")) .join(""); } async hashPassword(password: string): Promise { return hash(password, { algorithm: 2, }); } async verifyPassword(password: string, hash: string): Promise { return verify(hash, password); } }