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

@vonage/auth

Package Overview
Dependencies
Maintainers
37
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vonage/auth - npm Package Compare versions

Comparing version 1.0.3 to 1.0.4

dist/auth.js.map

73

dist/auth.js

@@ -1,14 +0,9 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Auth = void 0;
const jwt_1 = require("@vonage/jwt");
const crypto_1 = require("crypto");
const fs_1 = require("fs");
const types_1 = require("./types");
class Auth {
import { tokenGenerate } from '@vonage/jwt';
import { createHash, createHmac } from 'crypto';
import { existsSync, readFileSync } from 'fs';
import { AlgorithmTypes, } from './types';
export class Auth {
constructor(opts) {
// add additional methods to find auth
// also needs to handle private key, etc
this.getQueryParams = (params) => {
return Object.assign({ api_key: this.apiKey, api_secret: this.apiSecret }, params);
return { api_key: this.apiKey, api_secret: this.apiSecret, ...params };
};

@@ -20,11 +15,7 @@ this.createBasicHeader = () => {

this.createBearerHeader = () => {
return 'Bearer ' + (0, jwt_1.tokenGenerate)(this.applicationId, this.privateKey);
return 'Bearer ' + tokenGenerate(this.applicationId, this.privateKey);
};
this.createSignatureHash = (params) => {
const returnParams = Object.assign({ api_key: this.apiKey }, params);
// Add the current timestamp to the parameters list with the key 'timestamp'.
// This should be an integer containing the number of seconds since the epoch (UNIX time))
returnParams.timestamp = Math.floor(Date.now() / 1000).toString();
// Loop through each of the parameters, sorted by key.
// For every value in the parameter list, replace all instances of & and = with an underscore _.
const keys = Object.keys(returnParams);

@@ -34,3 +25,2 @@ const stringifiedParamsforSigning = keys

.map((keyName) => {
// Generate a string consisting of &akey=value
return `&${keyName}=${returnParams[keyName]

@@ -41,37 +31,24 @@ .toString()

.join('');
// For hash
// Add signature secret to the end of the string, directly after the last value.
// It should now look something like this: '&akey=value&bkey=value${your_signature_secret}'
// Now run the string through an md5 hash function
// convert the resulting bytes to a string of hexadecimal digits.
// This is your MD5 hash signature,
// Should be added to the HTTP parameters of your request as the 'sig' parameter.
if (this.signature.algorithm === types_1.AlgorithmTypes.md5hash) {
returnParams.sig = (0, crypto_1.createHash)('md5')
if (this.signature.algorithm === AlgorithmTypes.md5hash) {
returnParams.sig = createHash('md5')
.update(stringifiedParamsforSigning + this.signature.secret)
.digest('hex');
}
// For HMAC
// Create an HMAC generator with your desired algorithm and your signature secret as the key.
// Now run the string through an hmac generator
// convert the resulting bytes to a string of hexadecimal digits.
// This is your HMAC signature,
// Should be added to the HTTP parameters of your request as the sig parameter
if (this.signature.algorithm === types_1.AlgorithmTypes.md5hmac) {
returnParams.sig = (0, crypto_1.createHmac)('md5', this.signature.secret)
if (this.signature.algorithm === AlgorithmTypes.md5hmac) {
returnParams.sig = createHmac('md5', this.signature.secret)
.update(stringifiedParamsforSigning)
.digest('hex');
}
if (this.signature.algorithm === types_1.AlgorithmTypes.sha1hmac) {
returnParams.sig = (0, crypto_1.createHmac)('sha1', this.signature.secret)
if (this.signature.algorithm === AlgorithmTypes.sha1hmac) {
returnParams.sig = createHmac('sha1', this.signature.secret)
.update(stringifiedParamsforSigning)
.digest('hex');
}
if (this.signature.algorithm === types_1.AlgorithmTypes.sha256hmac) {
returnParams.sig = (0, crypto_1.createHmac)('sha256', this.signature.secret)
if (this.signature.algorithm === AlgorithmTypes.sha256hmac) {
returnParams.sig = createHmac('sha256', this.signature.secret)
.update(stringifiedParamsforSigning)
.digest('hex');
}
if (this.signature.algorithm === types_1.AlgorithmTypes.sha512hmac) {
returnParams.sig = (0, crypto_1.createHmac)('sha512', this.signature.secret)
if (this.signature.algorithm === AlgorithmTypes.sha512hmac) {
returnParams.sig = createHmac('sha512', this.signature.secret)
.update(stringifiedParamsforSigning)

@@ -82,9 +59,9 @@ .digest('hex');

};
this.apiKey = (opts === null || opts === void 0 ? void 0 : opts.apiKey) || '';
this.apiSecret = (opts === null || opts === void 0 ? void 0 : opts.apiSecret) || '';
this.signature = (opts === null || opts === void 0 ? void 0 : opts.signature) || null;
this.applicationId = (opts === null || opts === void 0 ? void 0 : opts.applicationId) || null;
if (opts === null || opts === void 0 ? void 0 : opts.privateKey) {
if ((0, fs_1.existsSync)(opts.privateKey)) {
opts.privateKey = (0, fs_1.readFileSync)(opts.privateKey).toString();
this.apiKey = opts?.apiKey || '';
this.apiSecret = opts?.apiSecret || '';
this.signature = opts?.signature || null;
this.applicationId = opts?.applicationId || null;
if (opts?.privateKey) {
if (existsSync(opts.privateKey)) {
opts.privateKey = readFileSync(opts.privateKey).toString();
}

@@ -100,2 +77,2 @@ if (opts.privateKey instanceof Buffer) {

}
exports.Auth = Auth;
//# sourceMappingURL=auth.js.map

@@ -1,7 +0,4 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Auth = exports.AlgorithmTypes = void 0;
const auth_1 = require("./auth");
Object.defineProperty(exports, "Auth", { enumerable: true, get: function () { return auth_1.Auth; } });
var types_1 = require("./types");
Object.defineProperty(exports, "AlgorithmTypes", { enumerable: true, get: function () { return types_1.AlgorithmTypes; } });
import { Auth } from './auth';
export { AlgorithmTypes, } from './types';
export { Auth };
//# sourceMappingURL=index.js.map
/// <reference types="node" />
export declare type AuthConstructor = new (opts?: AuthOpts) => AuthInterface;
export type AuthConstructor = new (opts?: AuthOpts) => AuthInterface;
export declare enum AlgorithmTypes {

@@ -4,0 +4,0 @@ md5hash = "MD5HASH",

@@ -1,6 +0,2 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AlgorithmTypes = void 0;
// MD5 HASH, MD5 HMAC, SHA1 HMAC, SHA-256 HMAC and SHA-512 HMAC.
var AlgorithmTypes;
export var AlgorithmTypes;
(function (AlgorithmTypes) {

@@ -12,2 +8,3 @@ AlgorithmTypes["md5hash"] = "MD5HASH";

AlgorithmTypes["sha512hmac"] = "SHA512HMAC";
})(AlgorithmTypes = exports.AlgorithmTypes || (exports.AlgorithmTypes = {}));
})(AlgorithmTypes || (AlgorithmTypes = {}));
//# sourceMappingURL=types.js.map
{
"name": "@vonage/auth",
"version": "1.0.3",
"description": "> TODO: description",
"version": "1.0.4",
"description": "Vonage Auth Package adds the correct authentication headers to requests to Vonage API's",
"homepage": "https://github.com/vonage/vonage-node-sdk/tree/master/packages/auth#readme",

@@ -22,24 +22,10 @@ "bugs": {

"build": "npm run clean && npm run compile",
"clean": "tsc -b --clean",
"compile": "tsc -p tsconfig.json",
"format": "prettier --write \"lib/**/*.ts\" \"__tests__/**/*.ts\"",
"lint": "tslint -p tsconfig.json",
"prepublishOnly": "npm run build && npm run test && npm run lint",
"test": "npx jest",
"test-watch": "npx jest --watch",
"preversion": "npm run lint",
"version": "npm run format && git add -A lib"
"clean": "npx shx rm -rf dist tsconfig.tsbuildinfo",
"compile": "npx tsc --build --verbose"
},
"dependencies": {
"@vonage/jwt": "^1.0.3"
"@vonage/jwt": "^1.0.4"
},
"devDependencies": {
"@types/jest": "^28.1.6",
"@types/node": "^18.6.4",
"nock": "^13.2.9",
"prettier": "^2.7.1",
"ts-jest": "^28.0.7",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0",
"typescript": "^4.7.4"
"@types/node": "^18.11.9"
},

@@ -49,3 +35,3 @@ "publishConfig": {

},
"gitHead": "3d01d2557edea29b54610d7ff7b07d186affb0f8"
"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