Comparing version 0.1.2 to 1.0.0-beta.1
@@ -1,54 +0,30 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _thirtyTwo = require('thirty-two'); | ||
var _thirtyTwo2 = _interopRequireDefault(_thirtyTwo); | ||
var _qrImage = require('qr-image'); | ||
var _qrImage2 = _interopRequireDefault(_qrImage); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var encode = function encode(secret) { | ||
return _thirtyTwo2.default.encode(secret); | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const thirty_two_1 = require("thirty-two"); | ||
const qr_image_1 = require("qr-image"); | ||
const encode = (secret) => { | ||
return thirty_two_1.default.encode(secret); | ||
}; | ||
var decode = function decode(base32secret) { | ||
return _thirtyTwo2.default.decode(base32secret); | ||
const decode = (base32secret) => { | ||
return thirty_two_1.default.decode(base32secret); | ||
}; | ||
var uri = function uri(_ref) { | ||
var user = _ref.user, | ||
issuer = _ref.issuer, | ||
secret = _ref.secret; | ||
secret = encode(secret); | ||
return 'otpauth://totp/' + issuer + ':' + user + '?secret=' + secret + '&issuer=' + issuer; | ||
const uri = ({ user, issuer, secret }) => { | ||
secret = encode(secret); | ||
return `otpauth://totp/${issuer}:${user}?secret=${secret}&issuer=${issuer}`; | ||
}; | ||
var qrcode = function qrcode(_ref2) { | ||
var user = _ref2.user, | ||
issuer = _ref2.issuer, | ||
secret = _ref2.secret; | ||
return _qrImage2.default.imageSync(uri({ | ||
user: user, | ||
issuer: issuer, | ||
secret: secret | ||
}), { | ||
type: 'svg', | ||
size: 5 | ||
}); | ||
const qrcode = ({ user, issuer, secret }) => { | ||
return qr_image_1.default.imageSync(uri({ | ||
user, | ||
issuer, | ||
secret | ||
}), { | ||
type: 'svg', | ||
size: 5 | ||
}); | ||
}; | ||
exports.default = { | ||
encode: encode, | ||
decode: decode, | ||
uri: uri, | ||
qrcode: qrcode | ||
}; | ||
encode, | ||
decode, | ||
uri, | ||
qrcode | ||
}; |
141
lib/hotp.js
@@ -1,79 +0,70 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _crypto = require('crypto'); | ||
var _crypto2 = _interopRequireDefault(_crypto); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var doubleDigits = [0, 2, 4, 6, 8, 1, 3, 5, 7, 9]; | ||
"use strict"; | ||
// https://tools.ietf.org/html/rfc4226 | ||
var digitsPower = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000]; | ||
var calcChecksum = function calcChecksum(num, digits) { | ||
var doubleDigit = true; | ||
var total = 0; | ||
while (0 < digits--) { | ||
var digit = parseInt(num % 10); | ||
num /= 10; | ||
if (doubleDigit) digit = doubleDigits[digit]; | ||
total += digit; | ||
doubleDigit = !doubleDigit; | ||
} | ||
var result = total % 10; | ||
if (result > 0) result = 10 - result; | ||
return result; | ||
}; | ||
var generate = function generate(_ref) { | ||
var secret = _ref.secret, | ||
movingFactor = _ref.movingFactor, | ||
codeDigits = _ref.codeDigits, | ||
addChecksum = _ref.addChecksum, | ||
truncationOffset = _ref.truncationOffset; | ||
if (secret) { | ||
if (!movingFactor) movingFactor = 0; | ||
if (!codeDigits) codeDigits = 6; | ||
if (!addChecksum) addChecksum = false; | ||
if (!truncationOffset) truncationOffset = -1; | ||
var result = ''; | ||
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; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const crypto = require("crypto"); | ||
const doubleDigits = [0, 2, 4, 6, 8, 1, 3, 5, 7, 9]; | ||
const digitsPower = [ | ||
1, | ||
10, | ||
100, | ||
1000, | ||
10000, | ||
100000, | ||
1000000, | ||
10000000, | ||
100000000 | ||
]; | ||
function calcChecksum(num, digits) { | ||
let doubleDigit = true; | ||
let total = 0; | ||
while (0 < digits--) { | ||
let digit = num % 10; | ||
num /= 10; | ||
if (doubleDigit) | ||
digit = doubleDigits[digit]; | ||
total += digit; | ||
doubleDigit = !doubleDigit; | ||
} | ||
var hmac = _crypto2.default.createHmac('sha1', secret); | ||
let result = total % 10; | ||
if (result > 0) | ||
result = 10 - result; | ||
return result; | ||
} | ||
function default_1(parameters) { | ||
let { secret, movingFactor, codeDigits, addChecksum, truncationOffset } = parameters; | ||
if (!secret) | ||
throw new Error('no secret value'); | ||
if (!movingFactor) | ||
movingFactor = 0; | ||
if (!codeDigits) | ||
codeDigits = 6; | ||
if (!addChecksum) | ||
addChecksum = false; | ||
if (!truncationOffset) | ||
truncationOffset = -1; | ||
let result; | ||
const digits = addChecksum ? codeDigits + 1 : codeDigits; | ||
const text = Buffer.alloc(8); | ||
for (let i = text.length - 1; i >= 0; i--) { | ||
text[i] = movingFactor & 0xff; | ||
movingFactor >>= 8; | ||
} | ||
const hmac = crypto.createHmac('sha1', secret); | ||
hmac.update(text); | ||
var hash = Buffer.from(hmac.digest('hex'), 'hex'); | ||
var offset = hash[hash.length - 1] & 0xf; | ||
if (0 <= truncationOffset && truncationOffset < hash.length - 4) offset = truncationOffset; | ||
var binary = (hash[offset] & 0x7f) << 24 | (hash[offset + 1] & 0xff) << 16 | (hash[offset + 2] & 0xff) << 8 | hash[offset + 3] & 0xff; | ||
var otp = binary % digitsPower[codeDigits]; | ||
if (addChecksum) otp = otp * 10 + calcChecksum(otp, codeDigits); | ||
const hash = Buffer.from(hmac.digest('hex'), 'hex'); | ||
let offset = hash[hash.length - 1] & 0xf; | ||
if (0 <= truncationOffset && truncationOffset < hash.length - 4) | ||
offset = truncationOffset; | ||
const binary = ((hash[offset] & 0x7f) << 24) | | ||
((hash[offset + 1] & 0xff) << 16) | | ||
((hash[offset + 2] & 0xff) << 8) | | ||
(hash[offset + 3] & 0xff); | ||
let otp = binary % digitsPower[codeDigits]; | ||
if (addChecksum) | ||
otp = otp * 10 + calcChecksum(otp, codeDigits); | ||
result = otp.toString(); | ||
while (result.length < digits) { | ||
result = '0' + result; | ||
}return result; | ||
} else { | ||
throw Error('No secret value'); | ||
} | ||
}; | ||
exports.default = { | ||
generate: generate | ||
}; | ||
while (result.length < digits) | ||
result = '0' + result; | ||
return result; | ||
} | ||
exports.default = default_1; |
@@ -1,34 +0,6 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _authenticator = require('./authenticator'); | ||
Object.defineProperty(exports, 'authenticator', { | ||
enumerable: true, | ||
get: function get() { | ||
return _interopRequireDefault(_authenticator).default; | ||
} | ||
}); | ||
var _hotp = require('./hotp'); | ||
Object.defineProperty(exports, 'hotp', { | ||
enumerable: true, | ||
get: function get() { | ||
return _interopRequireDefault(_hotp).default; | ||
} | ||
}); | ||
var _totp = require('./totp'); | ||
Object.defineProperty(exports, 'totp', { | ||
enumerable: true, | ||
get: function get() { | ||
return _interopRequireDefault(_totp).default; | ||
} | ||
}); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const hotp_1 = require("./hotp"); | ||
exports.hotp = hotp_1.default; | ||
const totp_1 = require("./totp"); | ||
exports.totp = totp_1.default; |
@@ -1,43 +0,22 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _hotp = require('./hotp'); | ||
var _hotp2 = _interopRequireDefault(_hotp); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var generate = function generate(_ref) { | ||
var secret = _ref.secret, | ||
time = _ref.time, | ||
timestamp = _ref.timestamp, | ||
codeDigits = _ref.codeDigits, | ||
addChecksum = _ref.addChecksum, | ||
truncationOffset = _ref.truncationOffset; | ||
if (secret) { | ||
if (!time) time = 30; | ||
if (timestamp && timestamp instanceof Date) timestamp = timestamp.getTime(); | ||
if (!timestamp) timestamp = new Date().getTime(); | ||
var movingFactor = Math.floor(timestamp / 1000 / time); | ||
return _hotp2.default.generate({ | ||
secret: secret, | ||
movingFactor: movingFactor, | ||
codeDigits: codeDigits, | ||
addChecksum: addChecksum, | ||
truncationOffset: truncationOffset | ||
"use strict"; | ||
// https://tools.ietf.org/html/rfc6238 | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const hotp_1 = require("./hotp"); | ||
function default_1(parameters) { | ||
let { secret, time, timestamp, codeDigits, addChecksum, truncationOffset } = parameters; | ||
if (!secret) | ||
throw new Error('no secret value'); | ||
if (!time) | ||
time = 30; | ||
if (!timestamp) | ||
timestamp = new Date().getTime(); | ||
const movingFactor = Math.floor(timestamp / 1000 / time); | ||
return hotp_1.default({ | ||
secret, | ||
movingFactor, | ||
codeDigits, | ||
addChecksum, | ||
truncationOffset | ||
}); | ||
} else { | ||
throw Error('No secret value'); | ||
} | ||
}; | ||
// https://tools.ietf.org/html/rfc6238 | ||
exports.default = { | ||
generate: generate | ||
}; | ||
} | ||
exports.default = default_1; |
{ | ||
"name": "node-otp", | ||
"version": "0.1.2", | ||
"main": "lib/index.js", | ||
"repository": "git@github.com:alessiodionisi/node-otp.git", | ||
"author": "Alessio Dionisi <hello@adns.io>", | ||
"description": "Node.js One-Time Password", | ||
"version": "1.0.0-beta.1", | ||
"license": "MIT", | ||
"keywords": ["otp", "two-factor", "rfc4226", "rfc6238"], | ||
"files": ["lib"], | ||
"main": "./lib/index.js", | ||
"types": "./lib/index.d.ts", | ||
"author": { | ||
"name": "Alessio Dionisi", | ||
"email": "hello@adns.io" | ||
}, | ||
"repository": "alessiodionisi/node-otp", | ||
"keywords": [ | ||
"otp", | ||
"two-factor", | ||
"rfc4226", | ||
"rfc6238" | ||
], | ||
"scripts": { | ||
"lint": "tslint --project .", | ||
"test": "jest", | ||
"lint": "eslint .", | ||
"test:coverage": "yarn run test -- --coverage", | ||
"test:coverage-server": "serve -o coverage/lcov-report", | ||
"build": "babel src -d lib", | ||
"prepublishOnly": "npm run build" | ||
"test:coverage": "yarn run test --coverage", | ||
"build": "tsc" | ||
}, | ||
"jest": { | ||
"testPathIgnorePatterns": ["node_modules", "lib"] | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "^6.24.1", | ||
"babel-eslint": "^7.2.3", | ||
"babel-jest": "^20.0.3", | ||
"babel-plugin-transform-object-rest-spread": "^6.23.0", | ||
"babel-preset-env": "^1.6.0", | ||
"babel-preset-flow": "^6.23.0", | ||
"eslint": "^4.2.0", | ||
"eslint-plugin-flowtype": "^2.35.0", | ||
"flow-bin": "^0.50.0", | ||
"@types/node": "^8.0.53", | ||
"jest": "^20.0.4", | ||
"jsdoc": "^3.5.3" | ||
}, | ||
"dependencies": { | ||
"qr-image": "^3.2.0", | ||
"thirty-two": "^1.0.2" | ||
"ts-node": "^3.3.0", | ||
"tslint": "^5.8.0", | ||
"tslint-config-standard": "^7.0.0", | ||
"typescript": "^2.6.1" | ||
} | ||
} |
@@ -1,4 +0,4 @@ | ||
# node-otp | ||
# Node.js One-Time Password | ||
[![NPMV](https://img.shields.io/npm/v/node-otp.svg?style=flat-square)](https://npmjs.org/package/node-otp) | ||
[![Travis](https://img.shields.io/travis/alessiodionisi/node-otp.svg?style=flat-square)](https://travis-ci.org/alessiodionisi/node-otp) | ||
[![Travis](https://img.shields.io/travis/adnsio/node-otp.svg?style=flat-square)](https://travis-ci.org/adnsio/node-otp) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
0
6
11
6672
163
4
1
- Removedqr-image@^3.2.0
- Removedthirty-two@^1.0.2
- Removedqr-image@3.2.0(transitive)
- Removedthirty-two@1.0.2(transitive)