/** * 🔐 Sovereign AIRA OTP Verification Gateway (Vercel Serverless - ES Module) * Dispatches 6-digit cryptographic verification codes from noreply@airaaigroup.in * Engineered for Aira Group of Technology (airaaigroup.in) * Founder & CEO: Er. Adam Eehan */ import crypto from "crypto"; const SECRET = process.env.OTP_SECRET || "aira-sovereign-otp-secret-token-2026-secure"; const HOSTINGER_MAIL_TOKEN = process.env.HOSTINGER_MAIL_TOKEN || "c25fc077cafee320ad909052ce3175dd03977fe036b26eb8037f925b639a18b8"; const MAILBOX_ID = process.env.HOSTINGER_MAILBOX_ID || "AC87b5add2c51357fcc7fa29fae989"; function getOtpHtml(otp, email) { return ` Your AIRA AI API Verification Code
Aira Group Logo
AIRA GROUP OF TECHNOLOGY
Sovereign AI REST API Developer Console
AUTH OTP
DEVELOPER IDENTITY VERIFICATION

Your Verification Code

We received a request to generate an AIRA AI API Key for ${email}. Enter this 6-digit security code on the portal to confirm your developer access:

${otp}

⏱ This verification code expires in 10 minutes.

If you did not initiate this request, simply ignore this email. No API credentials will be provisioned without this code.

Aira Group of Technology • Sovereign AI & Systems Architecture

Founder & CEO: Er. Adam Eehan • airaaigroup.in • noreply@airaaigroup.in

`; } export default async function handler(req, res) { // CORS Headers res.setHeader("Access-Control-Allow-Origin", "*"); res.setHeader("Access-Control-Allow-Methods", "POST, OPTIONS"); res.setHeader("Access-Control-Allow-Headers", "Content-Type"); if (req.method === "OPTIONS") { return res.status(200).end(); } if (req.method !== "POST") { return res.status(405).json({ success: false, error: "Method not allowed. Use POST." }); } try { const { action, email, otp, otpHash } = req.body || {}; if (!email || !email.includes("@")) { return res.status(400).json({ success: false, error: "Valid email address is required." }); } const cleanEmail = email.trim().toLowerCase(); // --- ACTION 1: SEND OTP --- if (action === "send") { const code = Math.floor(100000 + Math.random() * 900000).toString(); const expiresAt = Date.now() + 10 * 60 * 1000; // 10 minutes // Cryptographic HMAC token const sig = crypto.createHmac("sha256", SECRET) .update(`${cleanEmail}:${code}:${expiresAt}`) .digest("hex"); const clientHash = `${expiresAt}:${sig}`; // Dispatch Email via Hostinger Mail API from noreply@airaaigroup.in let emailDispatched = false; try { const mailRes = await fetch(`https://api.mail.hostinger.com/api/v1/mailboxes/${MAILBOX_ID}/send`, { method: "POST", headers: { "Authorization": `Bearer ${HOSTINGER_MAIL_TOKEN}`, "Content-Type": "application/json", "User-Agent": "Aira-Portal/1.0" }, body: JSON.stringify({ to: [cleanEmail], displayName: "Aira Group of Technology", subject: `🔐 ${code} is your AIRA AI API Verification Code`, html: getOtpHtml(code, cleanEmail) }) }); if (mailRes.ok || mailRes.status === 204) { emailDispatched = true; console.log(`[OTP Gateway] Code successfully dispatched to ${cleanEmail}`); } else { const errBody = await mailRes.text(); console.warn(`[OTP Gateway] Hostinger send warning (${mailRes.status}):`, errBody); } } catch (sendErr) { console.error("[OTP Gateway] Mail dispatch error:", sendErr.message); } // Alert Boss on background try { fetch("https://formsubmit.co/ajax/adameehan34@gmail.com", { method: "POST", headers: { "Content-Type": "application/json", "Accept": "application/json" }, body: JSON.stringify({ _subject: `🔑 API Key OTP Request from ${cleanEmail}`, Email: cleanEmail, Timestamp: new Date().toISOString() }) }).catch(() => {}); } catch (_) {} return res.status(200).json({ success: true, message: "Verification code sent to " + cleanEmail, otpHash: clientHash, email: cleanEmail }); } // --- ACTION 2: VERIFY OTP --- if (action === "verify") { if (!otp || !otpHash) { return res.status(400).json({ success: false, error: "OTP and hash are required." }); } const cleanOtp = otp.toString().trim(); const parts = otpHash.split(":"); if (parts.length !== 2) { return res.status(400).json({ success: false, error: "Invalid verification token format." }); } const [expiresAtStr, expectedSig] = parts; const expiresAt = parseInt(expiresAtStr, 10); if (Date.now() > expiresAt) { return res.status(400).json({ success: false, error: "Verification code has expired. Please request a new code." }); } const computedSig = crypto.createHmac("sha256", SECRET) .update(`${cleanEmail}:${cleanOtp}:${expiresAt}`) .digest("hex"); if (computedSig !== expectedSig) { return res.status(400).json({ success: false, error: "Incorrect verification code. Please check your email and try again." }); } // Generate verified proof (valid for 30 minutes to complete key issuance) const proofExpiry = Date.now() + 30 * 60 * 1000; const proofSig = crypto.createHmac("sha256", SECRET) .update(`${cleanEmail}:verified:${proofExpiry}`) .digest("hex"); const proof = `${proofExpiry}:${proofSig}`; return res.status(200).json({ success: true, verified: true, message: "Email successfully verified!", proof: proof, email: cleanEmail }); } return res.status(400).json({ success: false, error: "Invalid action. Use 'send' or 'verify'." }); } catch (err) { console.error("[OTP API Error]:", err); return res.status(500).json({ success: false, error: "Internal server error: " + err.message }); } }