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

@vonage/jwt

Package Overview
Dependencies
Maintainers
52
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vonage/jwt - npm Package Compare versions

Comparing version 1.7.0 to 1.8.0

dist/tokenGenerate.d.ts

1

dist/errors/index.js

@@ -21,2 +21,1 @@ "use strict";

__exportStar(require("./missingPrivateKeyError"), exports);
//# sourceMappingURL=index.js.map

@@ -0,3 +1,11 @@

/**
* InvalidMissingApplicationIdError` class for throwing an error when the
* application id is not a valid string. You can get the application ID from
* your developer dashboard. The ID will be a UUID that was generated when you
* created the application.
*
* @extends {Error}
*/
export declare class InvalidApplicationIdError extends Error {
constructor();
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.InvalidApplicationIdError = void 0;
/**
* InvalidMissingApplicationIdError` class for throwing an error when the
* application id is not a valid string. You can get the application ID from
* your developer dashboard. The ID will be a UUID that was generated when you
* created the application.
*
* @extends {Error}
*/
class InvalidApplicationIdError extends Error {

@@ -10,2 +18,1 @@ constructor() {

exports.InvalidApplicationIdError = InvalidApplicationIdError;
//# sourceMappingURL=invalidApplicationIdError.js.map

@@ -0,3 +1,12 @@

/**
* `InvalidPrivateKeyError` class for throwing an error when the private key
* is invalid. The private key must either be the string of the key or a buffer
* from the key file. When you created the application, the private key would
* have been downloaded then. If you lost the key, you will need to regenrate
* the key.
*
* @extends {Error}
*/
export declare class InvalidPrivateKeyError extends Error {
constructor();
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.InvalidPrivateKeyError = void 0;
/**
* `InvalidPrivateKeyError` class for throwing an error when the private key
* is invalid. The private key must either be the string of the key or a buffer
* from the key file. When you created the application, the private key would
* have been downloaded then. If you lost the key, you will need to regenrate
* the key.
*
* @extends {Error}
*/
class InvalidPrivateKeyError extends Error {

@@ -10,2 +19,1 @@ constructor() {

exports.InvalidPrivateKeyError = InvalidPrivateKeyError;
//# sourceMappingURL=invalidPrivateKeyError.js.map

@@ -0,3 +1,11 @@

/**
* `MissingApplicationIdError` class for throwing an error when the
* application id is missing. You can get the application ID from your developer
* dashboard. The ID will be a UUID that was generated when you created the
* application.
*
* @extends {Error}
*/
export declare class MissingApplicationIdError extends Error {
constructor();
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MissingApplicationIdError = void 0;
/**
* `MissingApplicationIdError` class for throwing an error when the
* application id is missing. You can get the application ID from your developer
* dashboard. The ID will be a UUID that was generated when you created the
* application.
*
* @extends {Error}
*/
class MissingApplicationIdError extends Error {

@@ -10,2 +18,1 @@ constructor() {

exports.MissingApplicationIdError = MissingApplicationIdError;
//# sourceMappingURL=missingApplicationIdError.js.map

@@ -0,3 +1,12 @@

/**
* `MissingPrivateKeyError` class for throwing an error when the private key
* is missing. The private key must either be the string of the key or a buffer
* from the key file. When you created the application, the private key would
* have been downloaded then. If you lost the key, you will need to regenrate
* the key.
*
* @extends {Error}
*/
export declare class MissingPrivateKeyError extends Error {
constructor();
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MissingPrivateKeyError = void 0;
/**
* `MissingPrivateKeyError` class for throwing an error when the private key
* is missing. The private key must either be the string of the key or a buffer
* from the key file. When you created the application, the private key would
* have been downloaded then. If you lost the key, you will need to regenrate
* the key.
*
* @extends {Error}
*/
class MissingPrivateKeyError extends Error {

@@ -10,2 +19,1 @@ constructor() {

exports.MissingPrivateKeyError = MissingPrivateKeyError;
//# sourceMappingURL=missingPrivateKeyError.js.map

@@ -1,8 +0,5 @@

/// <reference types="node" />
import { JWT } from './jwt';
import { GeneratorOptions } from './common';
export * from './errors/index';
export { JWT, GeneratorOptions };
export * from './acl';
export declare function tokenGenerate(applicationId: string, privateKey: string | Buffer, opts?: GeneratorOptions): string;
export declare function verifySignature(token: string, privateKey: string | Buffer): boolean;
export * from './errors';
export * from './tokenGenerate';
export * from './verifySignature';
export * from './types';
export * from './jwt';

@@ -17,16 +17,6 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.verifySignature = exports.tokenGenerate = exports.JWT = void 0;
const jwt_1 = require("./jwt");
Object.defineProperty(exports, "JWT", { enumerable: true, get: function () { return jwt_1.JWT; } });
__exportStar(require("./errors/index"), exports);
__exportStar(require("./acl"), exports);
const instance = new jwt_1.JWT();
function tokenGenerate(applicationId, privateKey, opts) {
return instance.tokenGenerate(applicationId, privateKey, opts);
}
exports.tokenGenerate = tokenGenerate;
function verifySignature(token, privateKey) {
return instance.verifySignature(token, privateKey);
}
exports.verifySignature = verifySignature;
//# sourceMappingURL=index.js.map
__exportStar(require("./errors"), exports);
__exportStar(require("./tokenGenerate"), exports);
__exportStar(require("./verifySignature"), exports);
__exportStar(require("./types"), exports);
__exportStar(require("./jwt"), exports);
/// <reference types="node" />
import { JWTInterface, GeneratorOptions } from './common';
import { GeneratorOptions } from './types';
/**
* Interface defining the methods for JWT generation.
*
* @ignore
* @deprecated Using the class is no longer needed
*/
export interface JWTInterface {
/**
* Generates a JWT token.
*
* @param {string} applicationId - The application ID.
* @param {string | Buffer} privateKey - The private key for signing the JWT.
* @param {GeneratorOptions} [opts] - Optional parameters for token generation.
* @returns {void}
*/
tokenGenerate(applicationId: string, privateKey: string | Buffer, opts?: GeneratorOptions): void;
}
/**
* Class implementing the JWTInterface for JWT operations.
*
* @ignore
* @deprecated Using the class is no longer needed
*/
export declare class JWT implements JWTInterface {
/**
* Generates a JWT token.
*
* @param {string} applicationId - The application ID.
* @param {string | Buffer} privateKey - The private key for signing the JWT.
* @param {GeneratorOptions} [opts] - Optional parameters for token generation.
* @return {string} - The generated JWT token.
*/
tokenGenerate(applicationId: string, privateKey: string | Buffer, opts?: GeneratorOptions): string;
/**
* Verifies the signature of a JWT token.
*
* @param {string} jwt - The JWT token to verify.
* @param {string | Buffer} privateKey - The private key used for verification.
* @return {boolean} - True if the signature is valid, false otherwise.
*/
verifySignature(jwt: string, privateKey: string | Buffer): boolean;
/**
* Validates the options provided for JWT generation.
*
* @param {GeneratorOptions} [opts] - The options to validate.
* @return {Claims} - The validated claims.
*/
private validateOptions;
}
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.JWT = void 0;
const jsonwebtoken_1 = require("jsonwebtoken");
const uuid_1 = require("uuid");
const index_1 = require("./errors/index");
const debug_1 = __importDefault(require("debug"));
const log = (0, debug_1.default)('vonage:jwt');
const tokenGenerate_1 = require("./tokenGenerate");
const verifySignature_1 = require("./verifySignature");
/**
* Class implementing the JWTInterface for JWT operations.
*
* @ignore
* @deprecated Using the class is no longer needed
*/
class JWT {
/**
* Generates a JWT token.
*
* @param {string} applicationId - The application ID.
* @param {string | Buffer} privateKey - The private key for signing the JWT.
* @param {GeneratorOptions} [opts] - Optional parameters for token generation.
* @return {string} - The generated JWT token.
*/
tokenGenerate(applicationId, privateKey, opts) {
log(`Application id: ${applicationId}`);
log(`Private key: ${privateKey}`);
if (!applicationId) {
throw new index_1.MissingApplicationIdError();
}
if (!privateKey) {
throw new index_1.MissingPrivateKeyError();
}
if (typeof applicationId !== 'string') {
throw new index_1.InvalidApplicationIdError();
}
if (typeof privateKey !== 'string' && !(privateKey instanceof Buffer)) {
throw new index_1.InvalidPrivateKeyError();
}
const claims = this.validateOptions(opts);
log('Claims', claims);
claims.application_id = applicationId;
return (0, jsonwebtoken_1.sign)(claims, privateKey, {
algorithm: 'RS256',
header: { typ: 'JWT', alg: 'RS256' },
});
return (0, tokenGenerate_1.tokenGenerate)(applicationId, privateKey, opts);
}
/**
* Verifies the signature of a JWT token.
*
* @param {string} jwt - The JWT token to verify.
* @param {string | Buffer} privateKey - The private key used for verification.
* @return {boolean} - True if the signature is valid, false otherwise.
*/
verifySignature(jwt, privateKey) {
try {
(0, jsonwebtoken_1.verify)(jwt, privateKey, {
algorithms: ['RS256'],
});
return true;
}
catch (error) {
log('Error when verifying token', error);
}
return false;
return (0, verifySignature_1.verifySignature)(jwt, privateKey);
}
/**
* Validates the options provided for JWT generation.
*
* @param {GeneratorOptions} [opts] - The options to validate.
* @return {Claims} - The validated claims.
*/
validateOptions(opts) {
const now = parseInt((Date.now() / 1000).toString(), 10);
const ttl = opts?.ttl || 900;
if (opts?.ttl) {
delete opts.ttl;
}
const claims = {
...opts,
jti: opts?.jti || (0, uuid_1.v4)(),
iat: opts?.issued_at || now,
exp: now + ttl,
};
if (opts?.subject) {
claims.sub = opts.subject;
}
if (opts?.acl) {
claims.acl = opts.acl;
}
for (const property in opts) {
// eslint-disable-next-line
if (opts.hasOwnProperty(property)) {
claims[property] = opts[property];
}
}
return claims;
return (0, tokenGenerate_1.validateOptions)(opts);
}
}
exports.JWT = JWT;
//# sourceMappingURL=jwt.js.map
{
"$schema": "https://json.schemastore.org/package.json",
"name": "@vonage/jwt",
"version": "1.7.0",
"version": "1.8.0",
"description": "Vonage JWT package. Creates JWT tokens for Vonage API's",

@@ -14,7 +15,20 @@ "homepage": "https://github.com/vonage/vonage-node-sdk/tree/master/packages/jwt#readme",

"license": "Apache-2.0",
"author": "Kelly J Andrews <kelly@kellyjandrews.com>",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"contributors": [
{
"name": "Kelly J Andrews",
"url": "https://github.com/kellyjandrews"
},
{
"name": "Chris Tankersley",
"url": "https://github.com/dragonmantank"
},
{
"name": "Chuck \"MANCHUCK\" Reeves",
"url": "https://github.com/manchuck"
}
],
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"files": [
"/dist"
"dist/**"
],

@@ -24,3 +38,4 @@ "scripts": {

"clean": "npx shx rm -rf dist tsconfig.tsbuildinfo",
"compile": "npx tsc --build --verbose"
"compile": "npx tsc --build --verbose",
"prepublishOnly": "npm run build"
},

@@ -33,2 +48,3 @@ "dependencies": {

"devDependencies": {
"@types/jsonwebtoken": "9.0.3",
"@types/uuid": "^9.0.5"

@@ -38,4 +54,3 @@ },

"directory": "dist"
},
"gitHead": "328f18e5c8a458cb4d06d7955ec2399a6ce6f5d8"
}
}
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