Socket
Socket
Sign inDemoInstall

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.0-3 to 10.0.0-4

18

authenticator.js

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

* @author Gerald Yeo <contact@fusedthought.com>
* @version: 10.0.0-3
* @version: 10.0.0-4
* @license: MIT

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

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; }

@@ -35,3 +33,6 @@ var base32 = _interopDefault(require('thirty-two'));

function encodeKey(secret) {
return base32.encode(secret).toString().replace(/=/g, '');
return base32
.encode(secret)
.toString()
.replace(/=/g, '');
}

@@ -42,3 +43,6 @@

const protocol = 'otpauth://totp/';
const value = data.replace('{user}', user).replace('{secret}', secret).replace(/{service}/g, service);
const value = data
.replace('{user}', user)
.replace('{secret}', secret)
.replace(/{service}/g, service);
return protocol + value;

@@ -108,2 +112,2 @@ }

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

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

* @author Gerald Yeo <contact@fusedthought.com>
* @version: 10.0.0-3
* @version: 10.0.0-4
* @license: MIT

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

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
Object.defineProperty(exports, '__esModule', { value: true });

@@ -51,3 +49,7 @@

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;
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);

@@ -74,9 +76,12 @@ token = otplibUtils.leftPad(token, options.digits);

function hotpOptions(options = {}) {
return _extends({
algorithm: 'sha1',
createHmacSecret: hotpSecret,
crypto: null,
digits: 6,
encoding: 'ascii'
}, options);
return Object.assign(
{
algorithm: 'sha1',
createHmacSecret: hotpSecret,
crypto: null,
digits: 6,
encoding: 'ascii'
},
options
);
}

@@ -121,5 +126,9 @@

function getWindowBounds(opt) {
const bounds = Array.isArray(opt.window) ? opt.window : [parseInt(opt.window, 10), parseInt(opt.window, 10)];
const 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'
);
}

@@ -129,3 +138,3 @@ return bounds;

function totpCheckWithWindow(token, secret, options) {
let opt = _extends({}, options);
let opt = Object.assign({}, options);
const bounds = getWindowBounds(opt);

@@ -154,3 +163,5 @@ const checker = createChecker(token, secret, opt);

default:
throw new Error(`Unsupported algorithm ${algorithm}. Accepts: sha1, sha256, sha512`);
throw new Error(
`Unsupported algorithm ${algorithm}. Accepts: sha1, sha256, sha512`
);
}

@@ -166,3 +177,3 @@ }

function totpOptions(options = {}) {
let opt = _extends(hotpOptions(), defaultOptions, options);
let opt = Object.assign(hotpOptions(), defaultOptions, options);
opt.epoch = typeof opt.epoch === 'number' ? opt.epoch * 1000 : Date.now();

@@ -183,2 +194,2 @@ return opt;

exports.totpSecret = totpSecret;
exports.totpToken = totpToken;
exports.totpToken = totpToken;

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

* @author Gerald Yeo <contact@fusedthought.com>
* @version: 10.0.0-3
* @version: 10.0.0-4
* @license: MIT

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

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var otplibCore = require('./core');

@@ -28,7 +26,7 @@

if (opt) {
this._options = _extends({}, this._options, opt);
this._options = Object.assign({}, this._options, opt);
}
}
get options() {
return _extends({}, this._options);
return Object.assign({}, this._options);
}

@@ -61,2 +59,2 @@ get optionsAll() {

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

@@ -114,10 +114,5 @@ interface hmacOptions {

declare module 'otplib' {
interface otplibModule {
authenticator: Authenticator;
hotp: HOTP;
totp: TOTP;
}
const otplib: otplibModule;
export = otplib;
const authenticator: Authenticator;
const hotp: HOTP;
const totp: TOTP;
}

@@ -141,19 +136,14 @@

declare module 'otplib/core' {
interface coreModule {
hotpCheck: hotpCheck;
hotpCounter: hotpCounter;
hotpDigest: hotpDigest;
hotpOptions: hotpOptions;
hotpSecret: hotpSecret;
hotpToken: hotpToken;
totpCheck: totpCheck;
totpCheckWithWindow: totpCheckWithWindow;
totpCounter: totpCounter;
totpOptions: totpOptions;
totpSecret: totpSecret;
totpToken: totpToken;
}
const core: coreModule;
export = core;
const hotpCheck: hotpCheck;
const hotpCounter: hotpCounter;
const hotpDigest: hotpDigest;
const hotpOptions: hotpOptions;
const hotpSecret: hotpSecret;
const hotpToken: hotpToken;
const totpCheck: totpCheck;
const totpCheckWithWindow: totpCheckWithWindow;
const totpCounter: totpCounter;
const totpOptions: totpOptions;
const totpSecret: totpSecret;
const totpToken: totpToken;
}

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

* @author Gerald Yeo <contact@fusedthought.com>
* @version: 10.0.0-3
* @version: 10.0.0-4
* @license: MIT

@@ -11,6 +11,6 @@ **/

function _interopDefault(ex) {
return ex && typeof ex === 'object' && 'default' in ex ? ex['default'] : ex;
}
Object.defineProperty(exports, '__esModule', { value: true });
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var hotp = _interopDefault(require('./hotp'));

@@ -24,8 +24,5 @@ var totp = _interopDefault(require('./totp'));

totp.options = { crypto };
var index = {
authenticator,
hotp,
totp
};
module.exports = index;
exports.hotp = hotp;
exports.totp = totp;
exports.authenticator = authenticator;
{
"name": "otplib",
"version": "10.0.0-3",
"version": "10.0.0-4",
"description": "HMAC-based (HOTP) and Time-based (TOTP) One-Time Password library",
"main": "./index.js",
"types": "./index.d.ts",
"typings": "./index.d.ts",
"scripts": {

@@ -11,4 +11,3 @@ "build": "./scripts/build.sh",

"build:docs": "jsdoc --configure jsdoc.json --verbose",
"build:module": "./scripts/build-module.sh",
"build:rollup": "rollup -c scripts/rollup.config.js",
"build:module": "rollup -c scripts/rollup.config.js",
"build:transpile": "babel dist --out-dir dist",

@@ -50,7 +49,4 @@ "build:types": "./scripts/build-types.sh",

"devDependencies": {
"babel-cli": "^6.26.0",
"babel-loader": "^7.1.3",
"babel-plugin-module-resolver": "^3.1.0",
"babel-plugin-transform-class-properties": "^6.23.0",
"babel-plugin-transform-object-assign": "^6.22.0",
"babel-preset-env": "^1.6.1",

@@ -66,5 +62,5 @@ "coveralls": "^3.0.0",

"minami": "^1.1.1",
"prettier": "1.12.1",
"prettier": "1.13.5",
"rimraf": "^2.6.1",
"rollup": "^0.59.0",
"rollup": "^0.60.0",
"rollup-plugin-cleanup": "^2.0.0",

@@ -78,6 +74,2 @@ "rollup-plugin-node-resolve": "^3.0.0",

},
"optionalDependencies": {
"@types/node": "latest",
"typescript": "next"
},
"jest": {

@@ -84,0 +76,0 @@ "coverageDirectory": "./coverage/",

@@ -12,2 +12,3 @@

---

@@ -17,2 +18,3 @@ - [About](#about)

- [Installation](#installation)
- [Type Definitions](#type-definitions)
- [Upgrading](#upgrading)

@@ -29,3 +31,2 @@ - [Getting Started](#getting-started)

- [Notes](#notes)
- [TypeScript Support](#typescript-support)
- [Setting Custom Options](#setting-custom-options)

@@ -69,2 +70,5 @@ - [Available Options](#available-options)

$ npm install otplib@next --save
# Additional dependencies for TypeScript
$ npm install @types/node
```

@@ -77,2 +81,6 @@

### Type Definitions
`TypeScript` support was introduced in `v10.0.0`
## Upgrading

@@ -191,3 +199,3 @@

```html
<script src="https://unpkg.com/otplib@^8.0.0/otplib-browser.js"></script>
<script src="https://unpkg.com/otplib@^10.0.0/otplib-browser.js"></script>
```

@@ -209,3 +217,3 @@

* with node crypto: ~311Kb
* with alternative crypto: ~96Kb
* with alternative crypto: ~106Kb

@@ -237,6 +245,2 @@ ## Advanced Usage

### TypeScript Support
As of `v10.0.0`, TypeScript definition files are included within the package.
### Setting Custom Options

@@ -276,9 +280,12 @@

| encoding | string | 'ascii' ('hex' for Authenticator) | The encoding of secret which is given to digest |
| epoch (totp) | integer | null | starting time since the UNIX epoch (seconds). _Note_ non-javascript epoch. i.e. `Date.now() / 1000` |
| epoch (totp) | integer | null | Starting time since the UNIX epoch (seconds). |
| step (totp) | integer | 30 | Time step (seconds) |
| window (totp) | integer or array | 0 | Tokens in the previous and future x-windows that should be considered valid. If integer, same value will be used for both. Alternatively, define array: `[previous, future]` |
_Note 1_: non "totp" label applies to all
_Note 2_: "totp" applies to authenticator as well
_Note 1_: epoch format is non-javascript. i.e. `Date.now() / 1000`
_Note 2_: non "totp" label applies to all
_Note 3_: "totp" applies to authenticator as well
### Seed / secret length

@@ -364,3 +371,3 @@

[coveralls-link]: https://coveralls.io/github/yeojz/otplib
[pr-welcome-badge]: https://img.shields.io/badge/welcome-PRs-brightgreen.svg?style=flat-square&longCache=true
[pr-welcome-badge]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square&longCache=true
[pr-welcome-link]: https://github.com/yeojz/otplib/blob/master/CONTRIBUTING.md

@@ -381,3 +388,3 @@ [mdn-uint8array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array

[coffee-link]: https://ko-fi.com/geraldyeo
[type-ts-badge]: https://img.shields.io/badge/included-.d.ts-blue.svg?style=flat-square&longCache=true
[type-ts-badge]: https://img.shields.io/badge/typedef-.d.ts-blue.svg?style=flat-square&longCache=true
[type-ts-link]: https://github.com/yeojz/otplib/tree/master/packages/types-ts

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

* @author Gerald Yeo <contact@fusedthought.com>
* @version: 10.0.0-3
* @version: 10.0.0-4
* @license: MIT

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

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; }

@@ -60,2 +58,2 @@ var otplibCore = require('./core');

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

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

* @author Gerald Yeo <contact@fusedthought.com>
* @version: 10.0.0-3
* @version: 10.0.0-4
* @license: MIT

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

if (size && len < size) {
const newSecret = new Array(size - len + 1).join(secretBuffer.toString('hex'));
const newSecret = new Array(size - len + 1).join(
secretBuffer.toString('hex')
);
return new Buffer(newSecret, 'hex').slice(0, size);

@@ -59,3 +61,6 @@ }

}
return options.crypto.randomBytes(length).toString('base64').slice(0, length);
return options.crypto
.randomBytes(length)
.toString('base64')
.slice(0, length);
}

@@ -91,2 +96,2 @@

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