// src/lib/turnstile.ts
var VERIFY_URL = "https://challenges.cloudflare.com/turnstile/v0/siteverify";
async function verifyTurnstile({
  c,
  config,
  token,
  action
}) {
  const turnstile = config.turnstile;
  if (!turnstile?.enabled) {
    return true;
  }
  if (!token?.trim()) {
    return false;
  }
  const body = new FormData();
  body.set("secret", turnstile.secretKey);
  body.set("response", token);
  const ip = c.req.header("cf-connecting-ip") || c.req.header("x-forwarded-for");
  if (ip) {
    body.set("remoteip", ip);
  }
  const response = await fetch(VERIFY_URL, { method: "POST", body });
  if (!response.ok) {
    return false;
  }
  const result = await response.json();
  if (!result.success) {
    return false;
  }
  return !(action && result.action && result.action !== action);
}
export {
  verifyTurnstile
};
//# sourceMappingURL=turnstile.js.map