import {
  getAuthConfigPath
} from "./chunk-CQGTEGKL.js";

// src/cli/auth.ts
import { readFile, writeFile, mkdir, access } from "fs/promises";
import { dirname } from "path";
import { createHash, publicEncrypt } from "crypto";
async function saveAuthConfig(mode, auth) {
  const authPath = getAuthConfigPath(mode);
  await mkdir(dirname(authPath), { recursive: true });
  await writeFile(authPath, JSON.stringify(auth, null, 2));
}
async function loadAuthConfig(mode) {
  const authPath = getAuthConfigPath(mode);
  try {
    const data = await readFile(authPath, "utf-8");
    return JSON.parse(data);
  } catch {
    return null;
  }
}
async function authConfigExists(mode) {
  const authPath = getAuthConfigPath(mode);
  try {
    await access(authPath);
    return true;
  } catch {
    return false;
  }
}
function encryptPassword(password, publicKey) {
  const encrypted = publicEncrypt({ key: publicKey, padding: 1 }, Buffer.from(password));
  return encrypted.toString("base64");
}
function hashPassword(password) {
  return createHash("sha256").update(password).digest("hex");
}
function verifyPassword(password, hash) {
  return hashPassword(password) === hash;
}
export {
  authConfigExists,
  encryptPassword,
  hashPassword,
  loadAuthConfig,
  saveAuthConfig,
  verifyPassword
};
//# sourceMappingURL=auth-56SIRACI.js.map