npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@jabz/security-utils

v6.0.1

Published

This is a utility package that combines using, 'bcrypt', 'crypto-js', 'jsonwebtoken' and 'object-hash' for storing information in a data base either by hash or encryption along with jwt management.

Downloads

36

Readme

SecurityUtils

This is a utility package that combines using 'bcrypt' 'crypto-js', 'jsonwebtoken' and 'object-hash' for storing information in a data base either by hash or encryption. It also supports the rotation of encryption to maintain compatibility when performing security key rotation.

4.0 >= hash had a major redesign. For previous version, check npm version and refer to the readme for each version.

Hash functions

There is a hash and compareHash functions which can be used for hash and salting passwords. This is done using bcrypt and object-has.

The expectation is to include a "pepperArray" which is an array of string. The dataTypes is then used to help select 3 unique strings from the array. Then those string are hashed together. A single character is then inserted into the hash string. The result is then hashed and pepper again (with different string generated from the pepper array) before finally salting the final value.

import {hashData, compareHash} from "@jabz/security-utils";

const inputData: any = {/*  any data you want  */}
const  dataType: number = 0 // used to provide variation
const  pepperString: string[] = [/* treat as api keys*/] // used for generating pepper
const hashData:string = hashData(inputData,  dataType: number, pepperString: string[]) // returns a hash string 
const compareHash = compareHash(hashData, dataType: number, hashString: string, pepperString: string[]) //returns boolean if match

JWT Manager

This is a class to help manage the generation and validation of JWTs. Instead of using jwtAPI keys for signing the token, this class will take up to 3 string from the kwt keys provided and hash a new one at run time.

import {JWTManager, JWTManagerConfig} from "@jabz/security-utils";
const keys = ()=>{/* some implementation to get the api keys*/};
const config : JWTManagerConfig  = {
    getJWTKey: () => string[];
    issuer: string;
    JWTConfig?: JWTConfig | undefined;
    accessTokenValidTime?: number
    refreshTokenValidTime?: number
};

const jwtManager = new JWTManager(config);

// the following are provided
    jwtManager.generateJWT(data: any) // values in the config are automatically injected. the data parameter can be used to override and inject any data field needed
    jwtManager.generateAccessToken(userID: string, options?: any, audience?: string) // used for making access token, options is used for injecting properties and overriding
    jwtManager.generateRefreshToken(userID: string, options?: any, audience?: string) // used for making refresh token, options is used for injecting properties and overriding
    jwtManager.verifyJWT (jwtString: string, audience?: string, subject?: string) // validates whether or not the jwt is authentic. Audience and Subject are optional
    jwtManager.decodeJWT(jwtString: string) // returns the data within a jwt
    jwtManager.deleteNoneUniqueJWTProperties({/*contents of a jwt*/} :any) // this is a utility function used to remove ALL "STANDARD" properties within a JWT leaving only custom properties.

Encryption Manager

With this class a "single encryption step" goes as follows:

  • pull 3
  • encrypt the data once
  • add a pepper
  • encrypt the data again

This library support a "single" encryption, N encryption and encryption fill objects.

import {EncryptionManager} from "@jabz/security-utils";
const getKeys: ()string[] => [/*your api keys*/] // used to get encryption keys
const encryptManager = new EncryptionManager(getKeys)

// the following are provided
    // used as a base wrapper around crypto-js for handling encryption. This is not intended to be used directly
    // encryptVar - used for variation when encryption, eg userID, specific field ...., this helps make two closely related data have completely different encryption keys
    encryptManager.singleEncryption(inputData: string, keyType: string | number, option?: string | number | undefined) 
    encryptManager.singleDecrypt(cipherText: string, keyType: string | number, option?: string | number | undefined)

    // this is the primary function intended to be used for encryption. This implements the described process above
    encryptManager.encryptText(inputData: string, keyType: string | number, pepperString: string[], option?: string | undefined)
    encryptManager.decryptData(cipherText: string, keyType: string | number, pepperString: string[], option?: string | undefined)

    // this applies the same encryption as above but does it so "N" times, the round number is the amount of times it will encrypt the data. The default is 2.
    encryptManager.NEncryption(inputData: string, keyType: string | number, option?: string | number | undefined, round?: number)
    encryptManager.NDecryption(cipherText: string, keyType: string | number, option?: string | number | undefined, round?: number)

    // this can be used to encrypt entire objects. This can only take objects that are a single layer of just primitives (booleans, numbers, strings). NaN is converted to null.
    encryptManager.encryptObjectData(data: acceptedObjectEncryption, keyType: string | number, pepperString: string[], optString?: string | number | undefined)
    encryptManager.decryptObject(encryptedObject: acceptedObjectEncryption, keyType: string | number, pepperString: string[], optString?: string | number | undefined)