forked from github/jsotp
add: basic function with comments
This commit is contained in:
parent
c8853d9ae8
commit
b144a14efe
@ -5,5 +5,11 @@
|
||||
*/
|
||||
|
||||
class Base32 {
|
||||
static decode() {
|
||||
console.log("static Base32.decode");
|
||||
}
|
||||
|
||||
static random_gen() {
|
||||
console.log("static Base32.random_gen");
|
||||
}
|
||||
}
|
44
src/hotp.js
44
src/hotp.js
@ -6,5 +6,47 @@
|
||||
import OTP from './otp';
|
||||
|
||||
class HOTP extends OTP {
|
||||
|
||||
/**
|
||||
* Generate the OTP with the given count
|
||||
*
|
||||
* @param {count}
|
||||
* @type {int}
|
||||
* @desc the OTP HMAC counter
|
||||
*
|
||||
* @return {OTP}
|
||||
*
|
||||
* @example
|
||||
* ```javascript
|
||||
* let hotp = jsotp.HOTP.gen('BASE32_ENCODED_SECRET');
|
||||
* hotp.at(0); // => 432143
|
||||
* ```
|
||||
*/
|
||||
at(count) {
|
||||
console.log("HOTP.at");
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies the OTP passed in against the current counter.
|
||||
*
|
||||
* @param {otp}
|
||||
* @type {String}
|
||||
* @desc the OTP waiting for checking
|
||||
*
|
||||
* @param {counter}
|
||||
* @type {int}
|
||||
* @desc the OTP HMAC counter
|
||||
*
|
||||
* @return {Boolean}
|
||||
*
|
||||
* @example
|
||||
* ```javascript
|
||||
* let hotp = jsotp.HOTP.gen('BASE32_ENCODED_SECRET');
|
||||
* hotp.at(0); // => 432143
|
||||
* hotp.verify(432143, 0); // => true
|
||||
* hotp.verify(432143, 1); // => false
|
||||
* ```
|
||||
*/
|
||||
verify(otp, counter) {
|
||||
console.log("HOTP.verify");
|
||||
}
|
||||
}
|
39
src/otp.js
39
src/otp.js
@ -4,17 +4,44 @@
|
||||
*/
|
||||
|
||||
export default class OTP {
|
||||
/**
|
||||
* This constructor will create OTP instance.
|
||||
*
|
||||
* @param {secret}
|
||||
* @type {String}
|
||||
* @desc random base32-encoded key, it is the
|
||||
* key that be used to verify.
|
||||
*
|
||||
* @param {digits}
|
||||
* @type {int}
|
||||
* @desc the length of the one-time password, default to be 6
|
||||
*
|
||||
* @param {digest}
|
||||
* @type {String}
|
||||
* @desc the key that be used to do HMAC encoding, dedault and
|
||||
* only to be "sha1"
|
||||
*
|
||||
*/
|
||||
constructor(secret, digits=6, digest="sha1") {
|
||||
/*
|
||||
* This constructor will create OTP instance
|
||||
*/
|
||||
this.secret = secret;
|
||||
this.digits = digits;
|
||||
this.digest = digest;
|
||||
};
|
||||
}
|
||||
|
||||
generate_otp() {
|
||||
/**
|
||||
* When class HOTP or TOTP pass the input params to this
|
||||
* function, it will generate the OTP object with params,
|
||||
* the params may be counter or time.
|
||||
*
|
||||
* @param {input}
|
||||
* @type {int}
|
||||
* @desc input params to generate OTP object, maybe
|
||||
* counter or time.
|
||||
*
|
||||
* @return {OTP}
|
||||
*/
|
||||
generate_otp(input) {
|
||||
console.log("OTP.generate_otp");
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
59
src/totp.js
59
src/totp.js
@ -3,6 +3,61 @@
|
||||
* @author : Gin (gin.lance.inside@hotmail.com)
|
||||
*/
|
||||
|
||||
class TOTP {
|
||||
|
||||
import OTP from './otp';
|
||||
|
||||
class TOTP extends OTP {
|
||||
/**
|
||||
* @param {interval}
|
||||
* @type {int}
|
||||
* @desc the time interval in seconds for OTP.
|
||||
* This defaults to 30.
|
||||
*
|
||||
* @return {OTP}
|
||||
*/
|
||||
constructor(interval=30, ...args) {
|
||||
this.interval = interval;
|
||||
super(...args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the OTP with current time.
|
||||
*
|
||||
* @return {OTP}
|
||||
*
|
||||
* @example
|
||||
* ```javascript
|
||||
* let totp = jsotp.TOTP.gen('BASE32_ENCODED_SECRET');
|
||||
* totp.now(); // => 432143
|
||||
* ```
|
||||
*/
|
||||
now() {
|
||||
console.log("TOTP.now");
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies the OTP passed in against the current time OTP.
|
||||
*
|
||||
* @param {otp}
|
||||
* @type {String}
|
||||
* @desc the OTP waiting for checking
|
||||
*
|
||||
* @param {time}
|
||||
* @type {int or datetime}
|
||||
* @desc Time to check OTP at (defaults to now)
|
||||
*
|
||||
* @return {Boolean}
|
||||
*
|
||||
* @example
|
||||
* ```javascript
|
||||
* let totp = jsotp.TOTP.gen('BASE32_ENCODED_SECRET');
|
||||
* totp.now(); // => 432143
|
||||
* // Verify for current time
|
||||
* totp.verify(432143); // => true
|
||||
* // Verify after 30s
|
||||
* totp.verify(432143); // => false
|
||||
* ```
|
||||
*/
|
||||
verify(otp, time=null) {
|
||||
console.log("TOTP.verify");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user