mirror of
https://github.com/LanceGin/jsotp.git
synced 2026-05-24 00:00:05 +08:00
upd: group the classes and export to one
This commit is contained in:
+35
-4
@@ -5,16 +5,47 @@
|
||||
* @Disc : a node module to generate and verify one-time passwords
|
||||
*/
|
||||
|
||||
import { OTP } from './otp';
|
||||
import { TOTP } from './totp';
|
||||
import { HOTP } from './hotp';
|
||||
import { Base32 } from './base32';
|
||||
import { Util } from './util';
|
||||
|
||||
/**
|
||||
* Generate and return HOTP object
|
||||
*
|
||||
* @param {secret}
|
||||
* @type {String}
|
||||
* @desc random base32-encoded key to generate OTP.
|
||||
*
|
||||
* @return {OTP}
|
||||
*/
|
||||
function hotp_gen(secret, digits=6, digest="SHA-1") {
|
||||
let hotp = new HOTP(secret, digits, digest);
|
||||
return hotp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate and return TOTP object
|
||||
*
|
||||
* @param {secret}
|
||||
* @type {String}
|
||||
* @desc random base32-encoded key to generate OTP.
|
||||
*
|
||||
* @param {interval}
|
||||
* @type {int}
|
||||
* @desc the time interval in seconds for OTP.
|
||||
* This defaults to 30.
|
||||
*
|
||||
* @return {OTP}
|
||||
*/
|
||||
function totp_gen(secret, interval=30) {
|
||||
let totp = new TOTP(secret, interval);
|
||||
return totp;
|
||||
}
|
||||
|
||||
export {
|
||||
OTP,
|
||||
TOTP,
|
||||
HOTP,
|
||||
hotp_gen as HOTP,
|
||||
totp_gen as TOTP,
|
||||
Base32,
|
||||
Util
|
||||
};
|
||||
Reference in New Issue
Block a user