X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=lib%2Ftotp.js;fp=lib%2Ftotp.js;h=aff5d961331caa33389f337efeef17122f6f53df;hb=607e23dda0fd320e36d8b7be27105b46ab584933;hp=15aa01e26e3ec13509b83060be109c527b907197;hpb=b071bd30e9464b1cf98fceead4508ee1e1b64544;p=squeep-totp diff --git a/lib/totp.js b/lib/totp.js index 15aa01e..aff5d96 100644 --- a/lib/totp.js +++ b/lib/totp.js @@ -5,15 +5,15 @@ const HOTP = require('./hotp'); class TimeBasedOneTimePassword extends HOTP { /** * - * @param {Object} options - * @param {Number} options.codeLength - * @param {Buffer|String} options.key - * @param {String} options.keyEncoding - * @param {String} options.algorithm - * @param {Number} options.timeStepSeconds - * @param {Number} options.timeStepStartSeconds - * @param {Number} options.driftForward - * @param {Number} options.driftBackward + * @param {object} options options + * @param {number} options.codeLength digits in code + * @param {Buffer|string} options.key secret key + * @param {string} options.keyEncoding secret key encoding + * @param {string} options.algorithm algorithm + * @param {number} options.timeStepSeconds seconds per increment + * @param {number} options.timeStepStartSeconds seconds offset + * @param {number} options.driftForward allowed future steps to check + * @param {number} options.driftBackward allowed past steps to check */ constructor(options) { const _options = { ...options }; @@ -35,6 +35,7 @@ class TimeBasedOneTimePassword extends HOTP { /** * The type used when constructing the otpauth URI. + * @returns {string} otp auth type */ static get _type() { return 'totp'; @@ -42,6 +43,7 @@ class TimeBasedOneTimePassword extends HOTP { /** * Derive counter from epoch. + * @returns {bigint} time based counter */ get counter() { const epoch = Math.floor(Date.now() / 1000); @@ -63,8 +65,8 @@ class TimeBasedOneTimePassword extends HOTP { /** * - * @param {BigInt=} count - * @returns {String} + * @param {bigint=} count counter value + * @returns {string} code */ generate(count = this.counter) { return super.generate(count); @@ -72,9 +74,9 @@ class TimeBasedOneTimePassword extends HOTP { /** * - * @param {String} hotp - * @param {BigInt=} count - * @returns {Boolean} + * @param {string} hotp code + * @param {bigint=} count counter value + * @returns {boolean} is valid */ validate(hotp, count) { const counter = count ?? this.counter;