import bcrypt from "bcryptjs";
import { SignJWT, jwtVerify } from "jose";
import { env } from "./env.js";
const secretKey = new TextEncoder().encode(env.jwtSecret);
export async function gerarHashSenha(senha) {
    return bcrypt.hash(senha, 10);
}
export async function verificarSenha(senha, hash) {
    return bcrypt.compare(senha, hash);
}
export async function emitirToken(payload) {
    return new SignJWT({ ...payload })
        .setProtectedHeader({ alg: "HS256" })
        .setIssuedAt()
        .setExpirationTime("30d")
        .sign(secretKey);
}
export async function verificarToken(token) {
    try {
        const { payload } = await jwtVerify(token, secretKey);
        return payload;
    }
    catch {
        return null;
    }
}
