add createKey and createKeySVG methods, support base32 key encoding
[squeep-totp] / lib / totp.js
index a305193e7dde085bc4ba7a76bef1814e1fa9acf6..a1d2fce6820afffc3a2d892565262666897f6363 100644 (file)
@@ -25,7 +25,7 @@ class TimeBasedOneTimePassword extends HOTP {
     ];
   }
 
-  get _algorithmKeyLengths() {
+  static get _algorithmKeyLengths() {
     return {
       ...super._algorithmKeyLengths,
       'sha256': 32,
@@ -33,14 +33,24 @@ class TimeBasedOneTimePassword extends HOTP {
     };
   }
 
+  /**
+   * The type used when constructing the otpauth URI.
+   */
+  static get _type() {
+    return 'totp';
+  }
+
+  /**
+   * Derive counter from epoch.
+   */
   get counter() {
     const epoch = Math.floor(Date.now() / 1000);
     return BigInt(Math.floor((epoch - this.timeStepStartSeconds) / this.timeStepSeconds));
   }
 
-  set counter(_) { /* */ }
+  set counter(_) { /* ignore assignment */ } // eslint-disable-line class-methods-use-this
 
-  get _defaultOptions() {
+  static get _defaultOptions() {
     const options = Object.assign(super._defaultOptions, {
       timeStepSeconds: 30,
       timeStepStartSeconds: 0,
@@ -51,6 +61,11 @@ class TimeBasedOneTimePassword extends HOTP {
     return options;
   }
 
+  /**
+   * 
+   * @param {BigInt=} count 
+   * @returns {String}
+   */
   generate(count = this.counter) {
     return super.generate(count);
   }
@@ -71,7 +86,7 @@ class TimeBasedOneTimePassword extends HOTP {
     }
     return false;
   }
-  
+
 }
 
 module.exports = TimeBasedOneTimePassword;