Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

otplib

Package Overview
Dependencies
Maintainers
1
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

otplib - npm Package Compare versions

Comparing version 10.0.1 to 10.1.0-0

164

authenticator.js

@@ -5,3 +5,3 @@ /**

* @author Gerald Yeo <contact@fusedthought.com>
* @version: 10.0.1
* @version: 10.1.0-0
* @license: MIT

@@ -11,4 +11,14 @@ **/

function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
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; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
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; }
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; }
function _interopDefault(ex) {
return ex && typeof ex === 'object' && 'default' in ex ? ex['default'] : ex;
}
var base32 = _interopDefault(require('thirty-two'));

@@ -23,8 +33,8 @@ var otplibCore = require('./core');

function checkDelta(token, secret, options) {
function _checkDelta(token, secret, options) {
return otplibCore.totpCheckWithWindow(token, decodeKey(secret), options);
}
function check(token, secret, options) {
const delta = checkDelta(token, secret, options);
function _check(token, secret, options) {
var delta = _checkDelta(token, secret, options);
return Number.isInteger(delta);

@@ -34,15 +44,13 @@ }

function encodeKey(secret) {
return base32
.encode(secret)
.toString()
.replace(/=/g, '');
return base32.encode(secret).toString().replace(/=/g, '');
}
const data = '{service}:{user}?secret={secret}&issuer={service}';
function keyuri(user = 'user', service = 'service', secret = '') {
const protocol = 'otpauth://totp/';
const value = data
.replace('{user}', user)
.replace('{secret}', secret)
.replace(/{service}/g, service);
var data = '{service}:{user}?secret={secret}&issuer={service}';
function _keyuri() {
var user = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'user';
var service = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'service';
var secret = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
var protocol = 'otpauth://totp/';
var value = data.replace('{user}', user).replace('{secret}', secret).replace(/{service}/g, service);
return protocol + value;

@@ -55,54 +63,84 @@ }

const TOTP = totp.TOTP;
class Authenticator extends TOTP {
constructor() {
super();
var TOTP = totp.TOTP;
var Authenticator = function (_TOTP) {
_inherits(Authenticator, _TOTP);
function Authenticator() {
_classCallCheck(this, Authenticator);
return _possibleConstructorReturn(this, (Authenticator.__proto__ || Object.getPrototypeOf(Authenticator)).call(this));
}
getClass() {
return Authenticator;
}
get defaultOptions() {
return {
encoding: 'hex',
epoch: null,
step: 30,
window: 0
};
}
encode(...args) {
return encodeKey(...args);
}
decode(...args) {
return decodeKey(...args);
}
keyuri(...args) {
return keyuri(...args);
}
generateSecret(len = 20) {
if (!len) {
return '';
_createClass(Authenticator, [{
key: 'getClass',
value: function getClass() {
return Authenticator;
}
const secret = otplibUtils.secretKey(len, this.optionsAll);
return encodeKey(secret);
}
generate(secret) {
const opt = this.optionsAll;
return token(secret || opt.secret, opt);
}
check(token$$1, secret) {
const opt = this.optionsAll;
return check(token$$1, secret || opt.secret, opt);
}
checkDelta(token$$1, secret) {
const opt = this.optionsAll;
return checkDelta(token$$1, secret || opt.secret, opt);
}
}
}, {
key: 'encode',
value: function encode() {
return encodeKey.apply(undefined, arguments);
}
}, {
key: 'decode',
value: function decode() {
return decodeKey.apply(undefined, arguments);
}
}, {
key: 'keyuri',
value: function keyuri() {
return _keyuri.apply(undefined, arguments);
}
}, {
key: 'generateSecret',
value: function generateSecret() {
var len = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 20;
if (!len) {
return '';
}
var secret = otplibUtils.secretKey(len, this.optionsAll);
return encodeKey(secret);
}
}, {
key: 'generate',
value: function generate(secret) {
var opt = this.optionsAll;
return token(secret || opt.secret, opt);
}
}, {
key: 'check',
value: function check(token$$1, secret) {
var opt = this.optionsAll;
return _check(token$$1, secret || opt.secret, opt);
}
}, {
key: 'checkDelta',
value: function checkDelta(token$$1, secret) {
var opt = this.optionsAll;
return _checkDelta(token$$1, secret || opt.secret, opt);
}
}, {
key: 'defaultOptions',
get: function get() {
return {
encoding: 'hex',
epoch: null,
step: 30,
window: 0
};
}
}]);
return Authenticator;
}(TOTP);
Authenticator.prototype.Authenticator = Authenticator;
Authenticator.prototype.utils = {
check,
checkDelta,
check: _check,
checkDelta: _checkDelta,
decodeKey,
encodeKey,
keyuri,
keyuri: _keyuri,
token

@@ -113,2 +151,2 @@ };

module.exports = index;
module.exports = index;

@@ -5,3 +5,3 @@ /**

* @author Gerald Yeo <contact@fusedthought.com>
* @version: 10.0.1
* @version: 10.1.0-0
* @license: MIT

@@ -16,3 +16,3 @@ **/

function hotpCounter(counter) {
const hexCounter = otplibUtils.intToHex(counter);
var hexCounter = otplibUtils.intToHex(counter);
return otplibUtils.leftPad(hexCounter, 16);

@@ -31,9 +31,9 @@ }

}
const hmacSecret = options.createHmacSecret(secret, {
var hmacSecret = options.createHmacSecret(secret, {
algorithm: options.algorithm,
encoding: options.encoding
});
const hexCounter = hotpCounter(counter);
const cryptoHmac = options.crypto.createHmac(options.algorithm, hmacSecret);
return cryptoHmac.update(new Buffer(hexCounter, 'hex')).digest();
var hexCounter = hotpCounter(counter);
var cryptoHmac = options.crypto.createHmac(options.algorithm, hmacSecret);
return cryptoHmac.update(Buffer.from(hexCounter, 'hex')).digest();
}

@@ -48,10 +48,6 @@

}
const digest = hotpDigest(secret, counter, options);
const offset = digest[digest.length - 1] & 0xf;
const binary =
((digest[offset] & 0x7f) << 24) |
((digest[offset + 1] & 0xff) << 16) |
((digest[offset + 2] & 0xff) << 8) |
(digest[offset + 3] & 0xff);
let token = binary % Math.pow(10, options.digits);
var digest = hotpDigest(secret, counter, options);
var offset = digest[digest.length - 1] & 0xf;
var binary = (digest[offset] & 0x7f) << 24 | (digest[offset + 1] & 0xff) << 16 | (digest[offset + 2] & 0xff) << 8 | digest[offset + 3] & 0xff;
var token = binary % Math.pow(10, options.digits);
token = otplibUtils.leftPad(token, options.digits);

@@ -62,3 +58,3 @@ return token;

function hotpCheck(token, secret, counter, options) {
const systemToken = hotpToken(secret, counter, options);
var systemToken = hotpToken(secret, counter, options);
if (systemToken.length < 1) {

@@ -74,16 +70,15 @@ return false;

}
return new Buffer(secret, options.encoding);
return Buffer.from(secret, options.encoding);
}
function hotpOptions(options = {}) {
return Object.assign(
{
algorithm: 'sha1',
createHmacSecret: hotpSecret,
crypto: null,
digits: 6,
encoding: 'ascii'
},
options
);
function hotpOptions() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
return Object.assign({
algorithm: 'sha1',
createHmacSecret: hotpSecret,
crypto: null,
digits: 6,
encoding: 'ascii'
}, options);
}

@@ -102,3 +97,3 @@

}
const counter = totpCounter(options.epoch, options.step);
var counter = totpCounter(options.epoch, options.step);
return hotpToken(secret, counter, options);

@@ -108,3 +103,3 @@ }

function totpCheck(token, secret, options) {
const systemToken = totpToken(secret, options || {});
var systemToken = totpToken(secret, options || {});
if (systemToken.length < 1) {

@@ -117,6 +112,6 @@ return false;

function createChecker(token, secret, opt) {
const delta = opt.step * 1000;
const epoch = opt.epoch;
return (direction, start, bounds) => {
for (let i = start; i <= bounds; i++) {
var delta = opt.step * 1000;
var epoch = opt.epoch;
return function (direction, start, bounds) {
for (var i = start; i <= bounds; i++) {
opt.epoch = epoch + direction * i * delta;

@@ -131,9 +126,5 @@ if (totpCheck(token, secret, opt)) {

function getWindowBounds(opt) {
const bounds = Array.isArray(opt.window)
? opt.window
: [parseInt(opt.window, 10), parseInt(opt.window, 10)];
var bounds = Array.isArray(opt.window) ? opt.window : [parseInt(opt.window, 10), parseInt(opt.window, 10)];
if (!Number.isInteger(bounds[0]) || !Number.isInteger(bounds[1])) {
throw new Error(
'Expecting options.window to be an integer or an array of integers'
);
throw new Error('Expecting options.window to be an integer or an array of integers');
}

@@ -143,6 +134,6 @@ return bounds;

function totpCheckWithWindow(token, secret, options) {
let opt = Object.assign({}, options);
const bounds = getWindowBounds(opt);
const checker = createChecker(token, secret, opt);
const backward = checker(-1, 0, bounds[0]);
var opt = Object.assign({}, options);
var bounds = getWindowBounds(opt);
var checker = createChecker(token, secret, opt);
var backward = checker(-1, 0, bounds[0]);
return backward !== null ? backward : checker(1, 1, bounds[1]);

@@ -158,4 +149,4 @@ }

}
const encoded = new Buffer(secret, options.encoding);
const algorithm = options.algorithm.toLowerCase();
var encoded = Buffer.from(secret, options.encoding);
var algorithm = options.algorithm.toLowerCase();
switch (algorithm) {

@@ -169,9 +160,7 @@ case 'sha1':

default:
throw new Error(
`Unsupported algorithm ${algorithm}. Accepts: sha1, sha256, sha512`
);
throw new Error(`Unsupported algorithm ${algorithm}. Accepts: sha1, sha256, sha512`);
}
}
const defaultOptions = {
var defaultOptions = {
createHmacSecret: totpSecret,

@@ -182,4 +171,6 @@ epoch: null,

};
function totpOptions(options = {}) {
let opt = Object.assign(hotpOptions(), defaultOptions, options);
function totpOptions() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var opt = Object.assign(hotpOptions(), defaultOptions, options);
opt.epoch = typeof opt.epoch === 'number' ? opt.epoch * 1000 : Date.now();

@@ -210,2 +201,2 @@ return opt;

exports.totpTimeUsed = totpTimeUsed;
exports.totpToken = totpToken;
exports.totpToken = totpToken;

@@ -5,3 +5,3 @@ /**

* @author Gerald Yeo <contact@fusedthought.com>
* @version: 10.0.1
* @version: 10.1.0-0
* @license: MIT

@@ -11,44 +11,73 @@ **/

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; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var otplibCore = require('./core');
class HOTP {
constructor() {
var HOTP = function () {
function HOTP() {
_classCallCheck(this, HOTP);
this._options = this.defaultOptions;
}
getClass() {
return HOTP;
}
get defaultOptions() {
return {};
}
set options(opt = {}) {
if (opt) {
this._options = Object.assign({}, this._options, opt);
_createClass(HOTP, [{
key: 'getClass',
value: function getClass() {
return HOTP;
}
}
get options() {
return Object.assign({}, this._options);
}
get optionsAll() {
return otplibCore.hotpOptions(this._options);
}
resetOptions() {
this._options = this.defaultOptions;
return this;
}
generate(secret, counter) {
const opt = this.optionsAll;
return otplibCore.hotpToken(secret || opt.secret, counter, opt);
}
check(token, secret, counter) {
const opt = this.optionsAll;
return otplibCore.hotpCheck(token, secret || opt.secret, counter, opt);
}
verify(opts) {
if (typeof opts !== 'object' || opts == null) {
return false;
}, {
key: 'resetOptions',
value: function resetOptions() {
this._options = this.defaultOptions;
return this;
}
return this.check(opts.token, opts.secret, opts.counter);
}
}
}, {
key: 'generate',
value: function generate(secret, counter) {
var opt = this.optionsAll;
return otplibCore.hotpToken(secret || opt.secret, counter, opt);
}
}, {
key: 'check',
value: function check(token, secret, counter) {
var opt = this.optionsAll;
return otplibCore.hotpCheck(token, secret || opt.secret, counter, opt);
}
}, {
key: 'verify',
value: function verify(opts) {
if (typeof opts !== 'object' || opts == null) {
return false;
}
return this.check(opts.token, opts.secret, opts.counter);
}
}, {
key: 'defaultOptions',
get: function get() {
return {};
}
}, {
key: 'options',
set: function set() {
var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
if (opt) {
this._options = Object.assign({}, this._options, opt);
}
},
get: function get() {
return Object.assign({}, this._options);
}
}, {
key: 'optionsAll',
get: function get() {
return otplibCore.hotpOptions(this._options);
}
}]);
return HOTP;
}();
HOTP.prototype.HOTP = HOTP;

@@ -58,2 +87,2 @@

module.exports = index;
module.exports = index;

@@ -1,2 +0,2 @@

interface hmacOptions {
interface HmacOptions {
algorithm?: string;

@@ -6,5 +6,5 @@ encoding?: string;

type createHmacSecret = (secret: string, options: hmacOptions) => Buffer;
type createHmacSecret = (secret: string, options: HmacOptions) => Buffer;
interface hotpOptionsInterface extends hmacOptions {
interface HotpOptionsInterface extends HmacOptions {
createHmacSecret?: createHmacSecret;

@@ -15,3 +15,3 @@ crypto?: any;

interface hotpVerifyOptionsInterface {
interface HotpVerifyOptionsInterface {
token?: string;

@@ -26,3 +26,3 @@ secret?: string;

counter: number,
options: hotpOptionsInterface
options: HotpOptionsInterface
) => boolean;

@@ -35,6 +35,6 @@

counter: number,
options: hotpOptionsInterface
options: HotpOptionsInterface
) => string;
type hotpOptions = (options: any) => hotpOptionsInterface;
type hotpOptions = (options: any) => HotpOptionsInterface;

@@ -46,6 +46,6 @@ type hotpSecret = createHmacSecret;

counter: number,
options: hotpOptionsInterface
options: HotpOptionsInterface
) => string;
interface totpOptionsInterface extends hotpOptionsInterface {
interface TotpOptionsInterface extends HotpOptionsInterface {
epoch?: any;

@@ -56,3 +56,3 @@ step?: number;

interface totpVerifyOptionsInterface {
interface TotpVerifyOptionsInterface {
token?: string;

@@ -65,3 +65,3 @@ secret?: string;

secret: string,
options: totpOptionsInterface
options: TotpOptionsInterface
) => boolean;

@@ -72,3 +72,3 @@

secret: string,
options: totpOptionsInterface
options: TotpOptionsInterface
) => number | null;

@@ -78,3 +78,3 @@

type totpOptions = (options: any) => totpOptionsInterface;
type totpOptions = (options: any) => TotpOptionsInterface;

@@ -87,3 +87,3 @@ type totpSecret = createHmacSecret;

type totpToken = (secret: string, options: totpOptionsInterface) => string;
type totpToken = (secret: string, options: TotpOptionsInterface) => string;

@@ -94,8 +94,8 @@ declare class HOTP {

options: totpOptionsInterface;
optionsAll: totpOptionsInterface;
options: TotpOptionsInterface;
optionsAll: TotpOptionsInterface;
resetOptions(): this;
generate(secret: string, counter: number): string;
check(token: string, secret: string, counter: number): boolean;
verify(opts: hotpVerifyOptionsInterface): boolean;
verify(opts: HotpVerifyOptionsInterface): boolean;
}

@@ -107,8 +107,8 @@

options: totpOptionsInterface;
optionsAll: totpOptionsInterface;
options: TotpOptionsInterface;
optionsAll: TotpOptionsInterface;
generate(secret: string): string;
check(token: string, secret: string): boolean;
checkDelta(token: string, secret: string): number | null;
verify(opts: totpVerifyOptionsInterface): boolean;
verify(opts: TotpVerifyOptionsInterface): boolean;
timeUsed(): number;

@@ -115,0 +115,0 @@ timeRemaining(): number;

@@ -5,3 +5,3 @@ /**

* @author Gerald Yeo <contact@fusedthought.com>
* @version: 10.0.1
* @version: 10.1.0-0
* @license: MIT

@@ -13,3 +13,5 @@ **/

function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
function _interopDefault(ex) {
return ex && typeof ex === 'object' && 'default' in ex ? ex['default'] : ex;
}

@@ -27,2 +29,2 @@ var hotp = _interopDefault(require('./hotp'));

exports.totp = totp;
exports.authenticator = authenticator;
exports.authenticator = authenticator;
{
"name": "otplib",
"version": "10.0.1",
"version": "10.1.0-0",
"description": "HMAC-based (HOTP) and Time-based (TOTP) One-Time Password library",

@@ -44,2 +44,3 @@ "main": "./index.js",

"devDependencies": {
"babel-cli": "^6.26.0",
"babel-loader": "^7.1.3",

@@ -52,3 +53,3 @@ "babel-plugin-module-resolver": "^3.1.0",

"eslint": "^5.0.0",
"eslint-config-prettier": "^2.9.0",
"eslint-config-prettier": "^3.0.0",
"eslint-plugin-prettier": "^2.6.0",

@@ -58,6 +59,6 @@ "jest": "^23.0.0",

"minami": "^1.1.1",
"prettier": "1.13.7",
"prettier": "1.14.2",
"rimraf": "^2.6.1",
"rollup": "^0.62.0",
"rollup-plugin-cleanup": "^2.0.0",
"rollup": "^0.64.0",
"rollup-plugin-cleanup": "^3.0.0",
"rollup-plugin-node-resolve": "^3.0.0",

@@ -83,3 +84,4 @@ "webpack": "^4.12.0",

"/node_modules/"
]
],
"testURL": "http://localhost"
},

@@ -86,0 +88,0 @@ "repl": [

@@ -5,3 +5,3 @@ /**

* @author Gerald Yeo <contact@fusedthought.com>
* @version: 10.0.1
* @version: 10.1.0-0
* @license: MIT

@@ -11,52 +11,90 @@ **/

function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
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; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
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; }
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; }
function _interopDefault(ex) {
return ex && typeof ex === 'object' && 'default' in ex ? ex['default'] : ex;
}
var otplibCore = require('./core');
var hotp = _interopDefault(require('./hotp'));
const HOTP = hotp.HOTP;
class TOTP extends HOTP {
constructor() {
super();
var HOTP = hotp.HOTP;
var TOTP = function (_HOTP) {
_inherits(TOTP, _HOTP);
function TOTP() {
_classCallCheck(this, TOTP);
return _possibleConstructorReturn(this, (TOTP.__proto__ || Object.getPrototypeOf(TOTP)).call(this));
}
getClass() {
return TOTP;
}
get defaultOptions() {
return {
epoch: null,
step: 30,
window: 0
};
}
get optionsAll() {
return otplibCore.totpOptions(this._options);
}
generate(secret) {
const opt = this.optionsAll;
return otplibCore.totpToken(secret || opt.secret, opt);
}
check(token, secret) {
const delta = this.checkDelta(token, secret);
return Number.isInteger(delta);
}
checkDelta(token, secret) {
const opt = this.optionsAll;
return otplibCore.totpCheckWithWindow(token, secret || opt.secret, opt);
}
verify(opts) {
if (typeof opts !== 'object' || opts == null) {
return false;
_createClass(TOTP, [{
key: 'getClass',
value: function getClass() {
return TOTP;
}
return this.check(opts.token, opts.secret);
}
timeRemaining() {
const opt = this.optionsAll;
return otplibCore.totpTimeRemaining(opt.epoch, opt.step);
}
timeUsed() {
const opt = this.optionsAll;
return otplibCore.totpTimeUsed(opt.epoch, opt.step);
}
}
}, {
key: 'generate',
value: function generate(secret) {
var opt = this.optionsAll;
return otplibCore.totpToken(secret || opt.secret, opt);
}
}, {
key: 'check',
value: function check(token, secret) {
var delta = this.checkDelta(token, secret);
return Number.isInteger(delta);
}
}, {
key: 'checkDelta',
value: function checkDelta(token, secret) {
var opt = this.optionsAll;
return otplibCore.totpCheckWithWindow(token, secret || opt.secret, opt);
}
}, {
key: 'verify',
value: function verify(opts) {
if (typeof opts !== 'object' || opts == null) {
return false;
}
return this.check(opts.token, opts.secret);
}
}, {
key: 'timeRemaining',
value: function timeRemaining() {
var opt = this.optionsAll;
return otplibCore.totpTimeRemaining(opt.epoch, opt.step);
}
}, {
key: 'timeUsed',
value: function timeUsed() {
var opt = this.optionsAll;
return otplibCore.totpTimeUsed(opt.epoch, opt.step);
}
}, {
key: 'defaultOptions',
get: function get() {
return {
epoch: null,
step: 30,
window: 0
};
}
}, {
key: 'optionsAll',
get: function get() {
return otplibCore.totpOptions(this._options);
}
}]);
return TOTP;
}(HOTP);
TOTP.prototype.TOTP = TOTP;

@@ -66,2 +104,2 @@

module.exports = index;
module.exports = index;

@@ -5,3 +5,3 @@ /**

* @author Gerald Yeo <contact@fusedthought.com>
* @version: 10.0.1
* @version: 10.1.0-0
* @license: MIT

@@ -22,3 +22,4 @@ **/

function isValidToken(value) {
return /^(\d+)(\.\d+)?$/.test(value);
return (/^(\d+)(\.\d+)?$/.test(value)
);
}

@@ -33,4 +34,4 @@ function isSameToken(token1, token2) {

function leftPad(value, length) {
const total = !length ? 0 : length;
let padded = value + '';
var total = !length ? 0 : length;
var padded = value + '';
while (padded.length < total) {

@@ -43,9 +44,7 @@ padded = '0' + padded;

function padSecret(secretBuffer, size, encoding) {
const secret = secretBuffer.toString(encoding);
const len = secret.length;
var secret = secretBuffer.toString(encoding);
var len = secret.length;
if (size && len < size) {
const newSecret = new Array(size - len + 1).join(
secretBuffer.toString('hex')
);
return new Buffer(newSecret, 'hex').slice(0, size);
var newSecret = new Array(size - len + 1).join(secretBuffer.toString('hex'));
return Buffer.from(newSecret, 'hex').slice(0, size);
}

@@ -55,3 +54,5 @@ return secretBuffer;

function removeSpaces(value = '') {
function removeSpaces() {
var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
if (value == null) {

@@ -63,3 +64,5 @@ return '';

function secretKey(length, options = {}) {
function secretKey(length) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
if (!length || length < 1) {

@@ -71,14 +74,14 @@ return '';

}
return options.crypto
.randomBytes(length)
.toString('base64')
.slice(0, length);
return options.crypto.randomBytes(length).toString('base64').slice(0, length);
}
function setsOf(value, amount = 4, divider = ' ') {
const num = parseInt(amount, 10);
function setsOf(value) {
var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 4;
var divider = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ' ';
var num = parseInt(amount, 10);
if (Number.isNaN(num) || typeof value !== 'string') {
return '';
}
const regex = new RegExp('.{1,' + amount + '}', 'g');
var regex = new RegExp('.{1,' + amount + '}', 'g');
return value.match(regex).join(divider);

@@ -88,6 +91,6 @@ }

function stringToHex(value) {
const val = value == null ? '' : value;
let hex = '';
let tmp = '';
for (let i = 0; i < val.length; i++) {
var val = value == null ? '' : value;
var hex = '';
var tmp = '';
for (var i = 0; i < val.length; i++) {
tmp = ('0000' + val.charCodeAt(i).toString(16)).slice(-2);

@@ -107,2 +110,2 @@ hex += '' + tmp;

exports.setsOf = setsOf;
exports.stringToHex = stringToHex;
exports.stringToHex = stringToHex;

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc