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

node-otp

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-otp - npm Package Compare versions

Comparing version 1.2.0 to 1.2.1

.prettierrc

47

lib/hotp.js
"use strict";
// https://tools.ietf.org/html/rfc4226
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const crypto = require("crypto");
const doubleDigits = [0, 2, 4, 6, 8, 1, 3, 5, 7, 9];
const digitsPower = [
var crypto = __importStar(require("crypto"));
var doubleDigits = [0, 2, 4, 6, 8, 1, 3, 5, 7, 9];
var digitsPower = [
1,

@@ -15,9 +22,9 @@ 10,

10000000,
100000000
100000000,
];
function calcChecksum(num, digits) {
let doubleDigit = true;
let total = 0;
var doubleDigit = true;
var total = 0;
while (0 < digits--) {
let digit = num % 10;
var digit = num % 10;
num /= 10;

@@ -29,3 +36,3 @@ if (doubleDigit)

}
let result = total % 10;
var result = total % 10;
if (result > 0)

@@ -36,3 +43,3 @@ result = 10 - result;

function default_1(parameters) {
let { secret, movingFactor, codeDigits, addChecksum, truncationOffset, hmacAlgorithm } = parameters;
var secret = parameters.secret, movingFactor = parameters.movingFactor, codeDigits = parameters.codeDigits, addChecksum = parameters.addChecksum, truncationOffset = parameters.truncationOffset, hmacAlgorithm = parameters.hmacAlgorithm;
if (!secret)

@@ -50,3 +57,3 @@ throw new Error('no secret value');

hmacAlgorithm = 'sha1';
let secretLength;
var secretLength;
if (hmacAlgorithm === 'sha1')

@@ -60,20 +67,23 @@ secretLength = 20;

throw new Error('algorithm not supported');
const digits = addChecksum ? codeDigits + 1 : codeDigits;
const text = Buffer.alloc(8);
for (let i = text.length - 1; i >= 0; i--) {
var digits = addChecksum ? codeDigits + 1 : codeDigits;
var text = Buffer.alloc(8);
for (var i = text.length - 1; i >= 0; i--) {
text[i] = movingFactor & 0xff;
movingFactor >>= 8;
}
const hash = crypto.createHmac(hmacAlgorithm.toLowerCase(), Buffer.alloc(secretLength, secret)).update(text).digest();
let offset = hash[hash.length - 1] & 0xf;
var hash = crypto
.createHmac(hmacAlgorithm.toLowerCase(), Buffer.alloc(secretLength, secret))
.update(text)
.digest();
var offset = hash[hash.length - 1] & 0xf;
if (0 <= truncationOffset && truncationOffset < hash.length - 4)
offset = truncationOffset;
const binary = ((hash[offset] & 0x7f) << 24) |
var binary = ((hash[offset] & 0x7f) << 24) |
((hash[offset + 1] & 0xff) << 16) |
((hash[offset + 2] & 0xff) << 8) |
(hash[offset + 3] & 0xff);
let otp = binary % digitsPower[codeDigits];
var otp = binary % digitsPower[codeDigits];
if (addChecksum)
otp = otp * 10 + calcChecksum(otp, codeDigits);
let result = otp.toString();
var result = otp.toString();
while (result.length < digits)

@@ -84,1 +94,2 @@ result = '0' + result;

exports.default = default_1;
//# sourceMappingURL=hotp.js.map
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const hotp_1 = require("./hotp");
var hotp_1 = __importDefault(require("./hotp"));
exports.hotp = hotp_1.default;
const totp_1 = require("./totp");
var totp_1 = __importDefault(require("./totp"));
exports.totp = totp_1.default;
//# sourceMappingURL=index.js.map
"use strict";
// https://tools.ietf.org/html/rfc6238
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const hotp_1 = require("./hotp");
var hotp_1 = __importDefault(require("./hotp"));
function default_1(parameters) {
let { secret, step, time, initialTime, codeDigits, hmacAlgorithm } = parameters;
var secret = parameters.secret, step = parameters.step, time = parameters.time, initialTime = parameters.initialTime, codeDigits = parameters.codeDigits, hmacAlgorithm = parameters.hmacAlgorithm;
if (!secret)

@@ -17,10 +20,11 @@ throw new Error('no secret value');

hmacAlgorithm = 'sha512';
const movingFactor = Math.floor((time - initialTime) / step);
var movingFactor = Math.floor((time - initialTime) / step);
return hotp_1.default({
secret,
movingFactor,
codeDigits,
hmacAlgorithm
secret: secret,
movingFactor: movingFactor,
codeDigits: codeDigits,
hmacAlgorithm: hmacAlgorithm,
});
}
exports.default = default_1;
//# sourceMappingURL=totp.js.map
{
"name": "node-otp",
"description": "Node.js One-Time Password",
"version": "1.2.0",
"version": "1.2.1",
"license": "MIT",

@@ -9,3 +9,3 @@ "main": "./lib/index.js",

"author": "Alessio Dionisi <hello@adns.io>",
"repository": "alessiodionisi/node-otp",
"repository": "github:adnsio/node-otp",
"keywords": [

@@ -18,19 +18,22 @@ "otp",

],
"jest": {
"coverageDirectory": "./coverage",
"collectCoverage": true,
"preset": "ts-jest",
"testEnvironment": "node"
},
"scripts": {
"lint": "tslint --project .",
"test": "jest",
"build": "tsc"
"build": "tsc",
"prettify": "prettier --write src/**/*.ts && prettier --write __tests__/**/*.ts"
},
"jest": {
"coverageDirectory": "./coverage/",
"collectCoverage": true
},
"devDependencies": {
"@types/node": "^8.0.53",
"jest": "^21.2.1",
"ts-node": "^3.3.0",
"tslint": "^5.8.0",
"tslint-config-standard": "^7.0.0",
"typescript": "^2.6.1"
"@types/jest": "^24.0.12",
"@types/node": "^12.0.0",
"jest": "^24.8.0",
"prettier": "^1.17.0",
"ts-jest": "^24.0.2",
"ts-node": "^8.1.0",
"typescript": "^3.4.5"
}
}

@@ -6,7 +6,6 @@ # Node OTP

[![JavaScript Style Guide](https://cdn.rawgit.com/standard/standard/master/badge.svg)](https://github.com/standard/standard)
Node.js One-Time Password library
## Features
- Zero Dependency

@@ -20,4 +19,5 @@ - TypeScript Definitions

## Installation
```bash
yarn add final-form
yarn add node-otp
```

@@ -28,9 +28,12 @@

```bash
npm install --save final-form
npm install --save node-otp
```
## Examples
```javascript
otp.hotp({
secret: '12345678901234567890'
const { hotp } = require('node-otp')
hotp({
secret: '12345678901234567890',
})

@@ -40,4 +43,6 @@ ```

```javascript
otp.totp({
secret: '12345678901234567890'
const { totp } = require('node-otp')
totp({
secret: '12345678901234567890',
})

@@ -51,12 +56,23 @@ ```

### `Parameters`
#### `secret: string | Buffer`
#### `movingFactor?: number`
Default value of `movingFactor` is 0
#### `codeDigits?: number`
Default value of `codeDigits` is 6
#### `addChecksum?: boolean`
Default value of `addChecksum` is false
#### `truncationOffset?: number`
Default value of `truncationOffset` is -1
#### `hmacAlgorithm?: 'sha1' | 'sha256' | 'sha512'`
Default value of `hmacAlgorithm` is sha1

@@ -67,13 +83,25 @@

### `totp: (parameters: Parameters) => string`
### `Parameters`
#### `secret: string | Buffer`
#### `step?: number`
Default value of `step` is 30
#### `time?: number`
Default value of `time` is 6
#### `initialTime?: number`
Default value of `initialTime` is 0
#### `codeDigits?: number`
Default value of `codeDigits` is 6
#### `hmacAlgorithm?: 'sha1' | 'sha256' | 'sha512'`
Default value of `hmacAlgorithm` is sha256
Default value of `hmacAlgorithm` is sha256

Sorry, the diff of this file is not supported yet

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