import crypto from 'crypto'; const RFC_4648 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"; export class TotpChecker { static async ValidateTotp(totpSecret, code) { if (!totpSecret && !code) return true; if ((!totpSecret && code) || (totpSecret && !code)) return false; return true; } static EncodeBase32(input) { let secret = []; for (let i of input) secret.push(RFC_4648[i % RFC_4648.length]); return secret.join(""); } static GenerateCode(optionsOrIssuer) { let options = typeof optionsOrIssuer === "string" ? { issuer: optionsOrIssuer } : optionsOrIssuer; options.digits = options.digits || 6; options.period = options.period || 30; options.algorithm = options.algorithm || "SHA-1"; options.label = encodeURIComponent(options.label || options.issuer); options.secretLength = options.secretLength || 13; const secretStr = TotpChecker.EncodeBase32(crypto.randomBytes(options.secretLength)); return { url: `otpauth://totp/${options.issuer}?issuer=${options.issuer}&secret=${secretStr}&digits=${options.digits}&period=${options.period}&algorithm=${options.algorithm}`, secret: secretStr }; } } //# sourceMappingURL=totpChecker.js.map