Skip to content

Commit

Permalink
refactor: remove unneccessary dependencies, migrate types to a separa…
Browse files Browse the repository at this point in the history
…te folder and update changelog
  • Loading branch information
sheldon-welinga committed Mar 2, 2023
1 parent a270387 commit ba08073
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 550 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# CHANGELOG

## 1.0.0 (Mar 2, 2023)
## 1.0.3 (Mar 2, 2023)

- Bug fixes and testing
- Initial public release
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# JWT Encrypt

A JWT encryption and decryption library for node server and web applications
A JWT encryption and decryption library for node applications

This library provides a more granular encryption as it strives solve the vulnarabilities in the crypto encryption and descryption by using the latest `createCipheriv` and `createDecipheriv` as per the deprecation notice on `createCipher` and `createDecipher` which is currently semantically insecure for all supported ciphers and fattally flawed for ciphers in counter mode such as `(CTR, GCM or CCM)`.

Expand Down
2 changes: 1 addition & 1 deletion __tests__/jwtEncrypt.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import jwte from '../index';

import type { EncryptionOptions } from '../utils';
import type { EncryptionOptions } from '../types';

describe('"sign" - signing a token asynchronously', () => {
describe('"sign" jwt token success', () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/util.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Cipher } from '../utils';

import type { EncryptionOptions } from '../utils';
import type { EncryptionOptions } from '../types';

describe('"Cipher"', () => {
describe('"Cipher.encrypt"', () => {
Expand Down
1 change: 0 additions & 1 deletion browserify-aes.d.ts

This file was deleted.

6 changes: 1 addition & 5 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ import jwt from 'jsonwebtoken';

import { Cipher } from './utils';

import type { EncryptionOptions } from './utils';

interface EncryptedData {
data?: string;
}
import type { EncryptedData, EncryptionOptions } from './types';

/**
* Encrypt jsonwebtoken (JWT)
Expand Down
1 change: 0 additions & 1 deletion jestconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"transform": {
"^.+\\.ts?$": "ts-jest"
},
"testEnvironment": "jsdom",
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"moduleFileExtensions": ["ts", "js", "json", "node"]
}
10 changes: 4 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "jwt-encrypt",
"version": "1.0.2",
"version": "1.0.3",
"private": false,
"description": "A JWT encryption and decryption library for node server and web applications",
"description": "A JWT encryption and decryption library for node applications",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"types": "lib/types/index.d.ts",
"files": [
"lib/**/*"
],
Expand Down Expand Up @@ -42,19 +42,17 @@
"version": "yarn run format && git add -A src"
},
"dependencies": {
"browserify-aes": "^1.2.0",
"buffer": "^6.0.3",
"jsonwebtoken": "^9.0.0"
},
"devDependencies": {
"@types/jest": "^29.4.0",
"@types/jsonwebtoken": "^9.0.1",
"@types/node": "^18.14.4",
"@typescript-eslint/eslint-plugin": "^5.54.0",
"@typescript-eslint/parser": "^5.54.0",
"eslint": "^8.35.0",
"eslint-config-prettier": "^8.6.0",
"jest": "^29.4.3",
"jest-environment-jsdom": "^29.4.3",
"prettier": "^2.8.4",
"rimraf": "^4.1.2",
"ts-jest": "^29.0.5",
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
"experimentalDecorators": true,
"emitDecoratorMetadata": true
},
"include": ["browserify-aes.d.ts", "index.ts"],
"include": ["index.ts"],
"exclude": ["node_modules", "*/__tests__/*", "**/*.test.ts"]
}
37 changes: 37 additions & 0 deletions types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
export type EncryptionAlgorithm = 'aes-128-cbc' | 'aes-192-cbc' | 'aes-256-cbc';
// TODO: Support the CCM and GCM algorithms
// | 'aes-128-ccm'
// | 'aes-192-ccm'
// | 'aes-256-ccm'
// | 'aes-128-gcm'
// | 'aes-192-gcm'
// | 'aes-256-gcm';

export interface EncryptionOptions {
/**
* key - a 16-bit, 24-bit, or 32-bit raw string used by the algorithms. The 16-bit string is used on algorithms that include 128. The 24-bit string is used on algorithms that include 192. The 32-bit string is used on algorithms that include 256
*/
key: string;
/**
* iv - a 16-bit raw string initialization vector
* Initialization vectors should be unpredictable and unique; ideally, they will be cryptographically random
* @link https://en.wikipedia.org/wiki/Initialization_vector
*/
iv: string;
/**
* algorithm - The cypher algorithm to be used to encrypt the payload
*/
algorithm: EncryptionAlgorithm;
}

export interface DecryptedResult {
[key: string]: unknown;
}

export interface EncryptedResult {
data: string;
}

export interface EncryptedData {
data?: string;
}
39 changes: 2 additions & 37 deletions utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,6 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import { createCipheriv, createDecipheriv } from 'browserify-aes';
import { Buffer } from 'buffer';

export type EncryptionAlgorithm = 'aes-128-cbc' | 'aes-192-cbc' | 'aes-256-cbc';
// TODO: Support the CCM and GCM algorithms
// | 'aes-128-ccm'
// | 'aes-192-ccm'
// | 'aes-256-ccm'
// | 'aes-128-gcm'
// | 'aes-192-gcm'
// | 'aes-256-gcm';

export interface EncryptionOptions {
/**
* key - a 16-bit, 24-bit, or 32-bit raw string used by the algorithms. The 16-bit string is used on algorithms that include 128. The 24-bit string is used on algorithms that include 192. The 32-bit string is used on algorithms that include 256
*/
key: string;
/**
* iv - a 16-bit raw string initialization vector
* Initialization vectors should be unpredictable and unique; ideally, they will be cryptographically random
* @link https://en.wikipedia.org/wiki/Initialization_vector
*/
iv: string;
/**
* algorithm - The cypher algorithm to be used to encrypt the payload
*/
algorithm: EncryptionAlgorithm;
}
import { createCipheriv, createDecipheriv } from 'crypto';

interface DecryptedResult {
[key: string]: unknown;
}

interface EncryptedResult {
data: string;
}
import type { EncryptionOptions, EncryptedResult, DecryptedResult } from '../types';

export class Cipher {
private static validateEncryptionOptions(options: EncryptionOptions) {
Expand Down
Loading

0 comments on commit ba08073

Please sign in to comment.