otplib 10.1.0-0 → 10.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "otplib",
3
- "version": "10.1.0-0",
3
+ "version": "10.2.3",
4
4
  "description": "HMAC-based (HOTP) and Time-based (TOTP) One-Time Password library",
5
5
  "main": "./index.js",
6
6
  "typings": "./index.d.ts",
@@ -14,7 +14,8 @@
14
14
  "lint:js": "eslint \"packages/**/**?(.spec|).js\"",
15
15
  "lint:format": "prettier --write \"{packages,scripts,site/scripts,site/public}/**/**.js\"",
16
16
  "lint:ts": "dtslint ./packages/types-ts",
17
- "test": "jest --coverage",
17
+ "test": "jest --coverage --runInBand",
18
+ "test:nocover": "jest",
18
19
  "test:watch": "jest --coverage --watch"
19
20
  },
20
21
  "repository": {
@@ -41,26 +42,27 @@
41
42
  },
42
43
  "homepage": "https://yeojz.github.io/otplib",
43
44
  "devDependencies": {
44
- "babel-cli": "^6.26.0",
45
- "babel-loader": "^7.1.3",
45
+ "@babel/cli": "^7.0.0",
46
+ "@babel/core": "^7.0.0",
47
+ "@babel/preset-env": "^7.0.0",
48
+ "babel-loader": "^8.0.0",
46
49
  "babel-plugin-module-resolver": "^3.1.0",
47
- "babel-preset-env": "^1.6.1",
48
50
  "coveralls": "^3.0.0",
49
51
  "create-hmac": "^1.1.4",
50
52
  "dtslint": "^0.3.0",
51
53
  "eslint": "^5.0.0",
52
54
  "eslint-config-prettier": "^3.0.0",
53
- "eslint-plugin-prettier": "^2.6.0",
54
- "jest": "^23.0.0",
55
+ "eslint-plugin-prettier": "^3.0.0",
56
+ "jest": "^24.0.0",
55
57
  "jsdoc": "^3.4.3",
56
58
  "minami": "^1.1.1",
57
- "prettier": "1.14.2",
59
+ "prettier": "1.16.1",
58
60
  "rimraf": "^2.6.1",
59
- "rollup": "^0.64.0",
61
+ "rollup": "^1.0.0",
60
62
  "rollup-plugin-cleanup": "^3.0.0",
61
- "rollup-plugin-node-resolve": "^3.0.0",
62
- "webpack": "^4.12.0",
63
- "webpack-cli": "^3.0.3"
63
+ "rollup-plugin-node-resolve": "^4.0.0",
64
+ "webpack": "^4.29.6",
65
+ "webpack-cli": "^3.2.3"
64
66
  },
65
67
  "dependencies": {
66
68
  "thirty-two": "1.0.2"
@@ -71,13 +73,17 @@
71
73
  "modulePaths": [
72
74
  "<rootDir>/packages/"
73
75
  ],
76
+ "modulePathIgnorePatterns": [
77
+ "<rootDir>/.*/__mocks__"
78
+ ],
74
79
  "roots": [
75
80
  "<rootDir>/packages/"
76
81
  ],
77
82
  "resetMocks": true,
78
83
  "setupFiles": [],
79
84
  "testPathIgnorePatterns": [
80
- "/node_modules/"
85
+ "/node_modules/",
86
+ "/packages/types-ts/"
81
87
  ],
82
88
  "testURL": "http://localhost"
83
89
  },
package/totp.js CHANGED
@@ -2,91 +2,103 @@
2
2
  * otplib-totp
3
3
  *
4
4
  * @author Gerald Yeo <contact@fusedthought.com>
5
- * @version: 10.1.0-0
5
+ * @version: 10.2.3
6
6
  * @license: MIT
7
7
  **/
8
8
  'use strict';
9
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
10
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
13
11
 
14
- 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; }
12
+ 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); } }
13
+
14
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
15
+
16
+ function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
17
+
18
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
15
19
 
16
- 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; }
20
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
21
+
22
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
23
+
24
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
17
25
 
18
26
  function _interopDefault(ex) {
19
27
  return ex && typeof ex === 'object' && 'default' in ex ? ex['default'] : ex;
20
28
  }
21
29
 
22
- var otplibCore = require('./core');
23
- var hotp = _interopDefault(require('./hotp'));
30
+ var otplibCore = require("./core");
31
+
32
+ var hotp = _interopDefault(require("./hotp"));
24
33
 
25
34
  var HOTP = hotp.HOTP;
26
35
 
27
- var TOTP = function (_HOTP) {
36
+ var TOTP =
37
+ /*#__PURE__*/
38
+ function (_HOTP) {
28
39
  _inherits(TOTP, _HOTP);
29
40
 
30
41
  function TOTP() {
42
+ var _this;
43
+
31
44
  _classCallCheck(this, TOTP);
32
45
 
33
- return _possibleConstructorReturn(this, (TOTP.__proto__ || Object.getPrototypeOf(TOTP)).call(this));
46
+ _this = _possibleConstructorReturn(this, _getPrototypeOf(TOTP).call(this));
47
+ _this._defaultOptions = {
48
+ epoch: null,
49
+ step: 30,
50
+ window: 0
51
+ };
52
+ _this._options = _this._defaultOptions;
53
+ return _this;
34
54
  }
35
55
 
36
56
  _createClass(TOTP, [{
37
- key: 'getClass',
57
+ key: "getClass",
38
58
  value: function getClass() {
39
59
  return TOTP;
40
60
  }
41
61
  }, {
42
- key: 'generate',
62
+ key: "generate",
43
63
  value: function generate(secret) {
44
64
  var opt = this.optionsAll;
45
65
  return otplibCore.totpToken(secret || opt.secret, opt);
46
66
  }
47
67
  }, {
48
- key: 'check',
68
+ key: "check",
49
69
  value: function check(token, secret) {
50
70
  var delta = this.checkDelta(token, secret);
51
71
  return Number.isInteger(delta);
52
72
  }
53
73
  }, {
54
- key: 'checkDelta',
74
+ key: "checkDelta",
55
75
  value: function checkDelta(token, secret) {
56
76
  var opt = this.optionsAll;
57
77
  return otplibCore.totpCheckWithWindow(token, secret || opt.secret, opt);
58
78
  }
59
79
  }, {
60
- key: 'verify',
80
+ key: "verify",
61
81
  value: function verify(opts) {
62
82
  if (typeof opts !== 'object' || opts == null) {
63
83
  return false;
64
84
  }
85
+
65
86
  return this.check(opts.token, opts.secret);
66
87
  }
67
88
  }, {
68
- key: 'timeRemaining',
89
+ key: "timeRemaining",
69
90
  value: function timeRemaining() {
70
91
  var opt = this.optionsAll;
71
92
  return otplibCore.totpTimeRemaining(opt.epoch, opt.step);
72
93
  }
73
94
  }, {
74
- key: 'timeUsed',
95
+ key: "timeUsed",
75
96
  value: function timeUsed() {
76
97
  var opt = this.optionsAll;
77
98
  return otplibCore.totpTimeUsed(opt.epoch, opt.step);
78
99
  }
79
100
  }, {
80
- key: 'defaultOptions',
81
- get: function get() {
82
- return {
83
- epoch: null,
84
- step: 30,
85
- window: 0
86
- };
87
- }
88
- }, {
89
- key: 'optionsAll',
101
+ key: "optionsAll",
90
102
  get: function get() {
91
103
  return otplibCore.totpOptions(this._options);
92
104
  }
@@ -96,7 +108,5 @@ var TOTP = function (_HOTP) {
96
108
  }(HOTP);
97
109
 
98
110
  TOTP.prototype.TOTP = TOTP;
99
-
100
111
  var index = new TOTP();
101
-
102
112
  module.exports = index;
package/utils.js CHANGED
@@ -2,12 +2,14 @@
2
2
  * otplib-utils
3
3
  *
4
4
  * @author Gerald Yeo <contact@fusedthought.com>
5
- * @version: 10.1.0-0
5
+ * @version: 10.2.3
6
6
  * @license: MIT
7
7
  **/
8
8
  'use strict';
9
9
 
10
- Object.defineProperty(exports, '__esModule', { value: true });
10
+ Object.defineProperty(exports, '__esModule', {
11
+ value: true
12
+ });
11
13
 
12
14
  function hexToInt(hex) {
13
15
  return parseInt(hex, 16);
@@ -18,32 +20,37 @@ function intToHex(value) {
18
20
  }
19
21
 
20
22
  function isValidToken(value) {
21
- return (/^(\d+)(\.\d+)?$/.test(value)
22
- );
23
+ return /^(\d+)(\.\d+)?$/.test(value);
23
24
  }
25
+
24
26
  function isSameToken(token1, token2) {
25
27
  if (isValidToken(token1) && isValidToken(token2)) {
26
28
  return String(token1) === String(token2);
27
29
  }
30
+
28
31
  return false;
29
32
  }
30
33
 
31
34
  function leftPad(value, length) {
32
35
  var total = !length ? 0 : length;
33
36
  var padded = value + '';
37
+
34
38
  while (padded.length < total) {
35
39
  padded = '0' + padded;
36
40
  }
41
+
37
42
  return padded;
38
43
  }
39
44
 
40
45
  function padSecret(secretBuffer, size, encoding) {
41
46
  var secret = secretBuffer.toString(encoding);
42
47
  var len = secret.length;
48
+
43
49
  if (size && len < size) {
44
50
  var newSecret = new Array(size - len + 1).join(secretBuffer.toString('hex'));
45
51
  return Buffer.from(newSecret, 'hex').slice(0, size);
46
52
  }
53
+
47
54
  return secretBuffer;
48
55
  }
49
56
 
@@ -53,6 +60,7 @@ function removeSpaces() {
53
60
  if (value == null) {
54
61
  return '';
55
62
  }
63
+
56
64
  return value.replace(/\s+/g, '');
57
65
  }
58
66
 
@@ -62,20 +70,23 @@ function secretKey(length) {
62
70
  if (!length || length < 1) {
63
71
  return '';
64
72
  }
73
+
65
74
  if (!options.crypto || typeof options.crypto.randomBytes !== 'function') {
66
75
  throw new Error('Expecting options.crypto to have a randomBytes function');
67
76
  }
77
+
68
78
  return options.crypto.randomBytes(length).toString('base64').slice(0, length);
69
79
  }
70
80
 
71
81
  function setsOf(value) {
72
82
  var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 4;
73
83
  var divider = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ' ';
74
-
75
84
  var num = parseInt(amount, 10);
85
+
76
86
  if (Number.isNaN(num) || typeof value !== 'string') {
77
87
  return '';
78
88
  }
89
+
79
90
  var regex = new RegExp('.{1,' + amount + '}', 'g');
80
91
  return value.match(regex).join(divider);
81
92
  }
@@ -84,10 +95,12 @@ function stringToHex(value) {
84
95
  var val = value == null ? '' : value;
85
96
  var hex = '';
86
97
  var tmp = '';
98
+
87
99
  for (var i = 0; i < val.length; i++) {
88
100
  tmp = ('0000' + val.charCodeAt(i).toString(16)).slice(-2);
89
101
  hex += '' + tmp;
90
102
  }
103
+
91
104
  return hex;
92
105
  }
93
106