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

generateotp-ts

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

generateotp-ts - npm Package Compare versions

Comparing version 1.0.4 to 1.0.5

2

lib/index.d.ts

@@ -6,3 +6,3 @@ export declare function generateOtp(digits: number, expiration?: string | number | undefined, secret?: string): {

export interface DecodedOtpPayload {
otp: number;
otp: string;
iat: number;

@@ -9,0 +9,0 @@ exp: number;

@@ -9,2 +9,3 @@ "use strict";

const crypto_1 = __importDefault(require("crypto"));
const bcrypt_1 = __importDefault(require("bcrypt"));
const default_secret = crypto_1.default.randomBytes(32).toString("hex");

@@ -17,7 +18,9 @@ function generateOtp(digits, expiration = undefined, secret = "") {

// Create a payload containing the OTP
const payload = { otp };
const payload = { otp: bcrypt_1.default.hashSync(otp.toString(), 10) };
// Encrypt the payload using JWT and set the desired expiration time
const token = jsonwebtoken_1.default.sign(payload, secret || default_secret, {
expiresIn: expiration,
});
const token = expiration
? jsonwebtoken_1.default.sign(payload, secret || default_secret, {
expiresIn: expiration,
})
: jsonwebtoken_1.default.sign(payload, secret || default_secret);
return { otp, token };

@@ -31,3 +34,3 @@ }

// Check if the user-provided OTP matches the OTP in the payload
if (decodedPayload.otp === otp) {
if (bcrypt_1.default.compareSync(otp.toString(), decodedPayload.otp)) {
return true;

@@ -34,0 +37,0 @@ }

{
"name": "generateotp-ts",
"version": "1.0.4",
"version": "1.0.5",
"description": "A TypeScript library for generating and verifying OTPs using JWT",

@@ -27,5 +27,7 @@ "main": "lib/index.js",

"dependencies": {
"bcrypt": "^5.1.0",
"jsonwebtoken": "^9.0.0"
},
"devDependencies": {
"@types/bcrypt": "^5.0.0",
"@types/jsonwebtoken": "^9.0.1",

@@ -32,0 +34,0 @@ "typescript": "^5.0.4"

import jwt from "jsonwebtoken";
import crypto from "crypto";
import bcrypt from "bcrypt";

@@ -17,8 +18,10 @@ const default_secret = crypto.randomBytes(32).toString("hex");

// Create a payload containing the OTP
const payload = { otp };
const payload = { otp: bcrypt.hashSync(otp.toString(), 10) };
// Encrypt the payload using JWT and set the desired expiration time
const token = jwt.sign(payload, secret || default_secret, {
expiresIn: expiration,
});
const token = expiration
? jwt.sign(payload, secret || default_secret, {
expiresIn: expiration,
})
: jwt.sign(payload, secret || default_secret);

@@ -29,3 +32,3 @@ return { otp, token };

export interface DecodedOtpPayload {
otp: number;
otp: string;
iat: number;

@@ -48,3 +51,3 @@ exp: number;

// Check if the user-provided OTP matches the OTP in the payload
if (decodedPayload.otp === otp) {
if (bcrypt.compareSync(otp.toString(), decodedPayload.otp)) {
return true;

@@ -51,0 +54,0 @@ } else {

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