1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | 'use strict';
|
9 |
|
10 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
11 |
|
12 | var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
13 |
|
14 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
15 |
|
16 | function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
17 |
|
18 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
19 |
|
20 | function _interopDefault(ex) {
|
21 | return ex && (typeof ex === 'undefined' ? 'undefined' : _typeof(ex)) === 'object' && 'default' in ex ? ex['default'] : ex;
|
22 | }
|
23 |
|
24 | var otplibCore = require('./core');
|
25 | var hotp = _interopDefault(require('./hotp'));
|
26 |
|
27 | var HOTP = hotp.HOTP;
|
28 |
|
29 | var TOTP = function (_HOTP) {
|
30 | _inherits(TOTP, _HOTP);
|
31 |
|
32 | function TOTP() {
|
33 | _classCallCheck(this, TOTP);
|
34 |
|
35 | return _possibleConstructorReturn(this, (TOTP.__proto__ || Object.getPrototypeOf(TOTP)).call(this));
|
36 | }
|
37 |
|
38 | _createClass(TOTP, [{
|
39 | key: 'generate',
|
40 | value: function generate(secret) {
|
41 | return otplibCore.totpToken(secret || this.options.secret, this.options);
|
42 | }
|
43 | }, {
|
44 | key: 'check',
|
45 | value: function check(token, secret) {
|
46 | return otplibCore.totpCheck(token, secret || this.options.secret, this.options);
|
47 | }
|
48 | }, {
|
49 | key: 'verify',
|
50 | value: function verify(opts) {
|
51 | if ((typeof opts === 'undefined' ? 'undefined' : _typeof(opts)) !== 'object' || opts == null) {
|
52 | return false;
|
53 | }
|
54 | return this.check(opts.token, opts.secret);
|
55 | }
|
56 | }, {
|
57 | key: 'defaultOptions',
|
58 | get: function get() {
|
59 | return {
|
60 | epoch: null,
|
61 | step: 30
|
62 | };
|
63 | }
|
64 | }]);
|
65 |
|
66 | return TOTP;
|
67 | }(HOTP);
|
68 |
|
69 | TOTP.prototype.TOTP = TOTP;
|
70 |
|
71 | var index = new TOTP();
|
72 |
|
73 | module.exports = index; |
\ | No newline at end of file |