-
Notifications
You must be signed in to change notification settings - Fork 15
/
jsotp.js
51 lines (47 loc) · 1.03 KB
/
jsotp.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
* @project : jsotp
* @author : Gin (gin.lance.inside@hotmail.com)
* @link : https://github.com/LanceGin/jsotp
* @Disc : a node module to generate and verify one-time passwords
*/
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') {
const 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) {
const totp = new TOTP(secret, interval);
return totp;
}
export {
hotp_gen as HOTP,
totp_gen as TOTP,
Base32,
Util,
};