{"size": 601, "ext": "js", "max_stars_repo_path": "server/lib/otp.js", "max_stars_repo_name": "DEFRA/flood-xws-contact-web", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "server/lib/otp.js", "max_issues_repo_name": "DEFRA/flood-xws-contact-web", "max_issues_repo_issues_event_min_datetime": "2021-08-25T14:36:42.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-25T14:43:13.000Z", "max_forks_repo_path": "server/lib/otp.js", "max_forks_repo_name": "DEFRA/flood-xws-contact-web", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 23.1153846154, "max_line_length": 66, "alphanum_fraction": 0.68718802}
const { totp } = require('otplib')

// Tokens valid for 10 mins
totp.options = { step: 10 * 60 } // seconds

/**
 * Generate a time-based one-time password
 * @param {string} secret - A secret string
 */
function generateTOTP (secret) {
  const token = totp.generate(secret)
  return token
}

/**
 * Verify a time-based one-time password
 * @param {string} token - The time-based one-time password (TOTP)
 * @param {string} secret - A secret string
 */
function verifyTOTP (token, secret) {
  const isValid = totp.check(token, secret)
  return isValid
}

module.exports = { generateTOTP, verifyTOTP }
