import { hash, verify } from "@node-rs/argon2";

/**
 * argon2id mit OWASP-Minima (Querschnittsstandard 11):
 * type=argon2id (2), memoryCost >= 19456 KiB, timeCost >= 2, parallelism >= 1.
 *
 * WICHTIG: Dieses Modul NIE im Edge-/Middleware-Pfad importieren — @node-rs/argon2
 * ist ein natives Node-Modul.
 */
export const ARGON2_PARAMS = {
  type: 2 as const, // 2 === argon2id
  memoryCost: 19456,
  timeCost: 2,
  parallelism: 1,
};

export const hashPassword = (pw: string): Promise<string> =>
  hash(pw, ARGON2_PARAMS);

export const verifyPassword = (h: string, pw: string): Promise<boolean> =>
  verify(h, pw, ARGON2_PARAMS);
