Skip to content

Latest commit

 

History

History
55 lines (42 loc) · 1.92 KB

README.md

File metadata and controls

55 lines (42 loc) · 1.92 KB

ES6-HOTP-TOTP

ES6 implementation of HOTP and TOTP


Handles generation of HMAC-based One-time Password Algorithm (HOTP) codes as per the HOTP RFC Draft and the Time-based One-time Password Algorithm (TOTP) codes as per the TOTP RFC Draft. This library produces the same codes as the Google Authenticator app.

This package exports OTP and is based on this implementation jiangts JS-OTP.

Dependencies jsSHA. You can get jsSHA from NPM.

Usage:

Import src/OTP.js to your script like.

import {OTP} from './src/OTP.js'

    
/***
 * Configure TOTP settings for all or any timecode (optional)
 * @param {Number} expiry - <in seconds> defaults to 30
 * @param {Number} length - (between 6 and 8 ) defaults to 6
 */
OTP.configTotp(expiry, length);
 
/**
 * hotp usage
 * @param {String} otpKey - <your OTP key>
 * @param {Number} counter - <counter>
 */
const hmacCode = OTP.getHotp(otpKey, counter);

/**
 * totp usage
 * @param {String} otpKey - <your OTP key>
 * @param {Number} time - <milliseconds time> OPTIONAL. Defaults to new Date().getTime()
 */
const timeCode = OTP.getTotp(otpKey, time);

Fixes / Improvements:

  • [Fixed] deprecated function calls like escape
  • [Improvement] added global configuration for TOTP
  • [Fixed] exposing methods to global scope

TO DO

  • Better handling of errors

TO DO if requested

  • Add example build script for ES6
  • Add cordova example usage
  • Add angular 1.6+ example
  • Add angular 2 example
  • Add ng-cordova example
  • Add ampersand.js example with model usage
  • Add test
  • Add dist