Comparing version 2.0.0 to 2.1.0
{ | ||
"name": "bcrypt-ts", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "bcrypt written in typescript", | ||
@@ -18,8 +18,11 @@ "keywords": [ | ||
"types": "./dist/index.d.ts", | ||
"import": "./dist/index.esm.js", | ||
"require": "./dist/index.js", | ||
"default": "./dist/index.esm.js" | ||
"browser": "./dist/browser.mjs", | ||
"node": "./dist/node.mjs", | ||
"import": "./dist/node.mjs", | ||
"require": "./dist/node.cjs", | ||
"default": "./dist/node.mjs" | ||
}, | ||
"main": "dist/index.js", | ||
"module": "dist/index.esm.js", | ||
"main": "./dist/node.cjs", | ||
"module": "./dist/node.mjs", | ||
"browser": "./dist/browser.mjs", | ||
"types": "./dist/index.d.ts", | ||
@@ -32,26 +35,31 @@ "files": [ | ||
"devDependencies": { | ||
"@rollup/plugin-typescript": "^8.3.4", | ||
"@types/jest": "^28.1.7", | ||
"@types/node": "^18.7.11", | ||
"@typescript-eslint/eslint-plugin": "^5.34.0", | ||
"@typescript-eslint/parser": "^5.34.0", | ||
"eslint": "^8.22.0", | ||
"eslint-config-prettier": "^8.5.0", | ||
"eslint-plugin-prettier": "^4.2.1", | ||
"jest": "^28.1.3", | ||
"prettier": "^2.7.1", | ||
"rollup": "^2.78.1", | ||
"rollup-plugin-dts": "^4.2.2", | ||
"rollup-plugin-terser": "^7.0.2", | ||
"ts-jest": "^28.0.8", | ||
"tslib": "^2.4.0", | ||
"typescript": "^4.7.4" | ||
"@rollup/plugin-alias": "3.1.9", | ||
"@rollup/plugin-replace": "4.0.0", | ||
"@rollup/plugin-typescript": "8.3.4", | ||
"@types/node": "18.7.11", | ||
"@typescript-eslint/eslint-plugin": "5.34.0", | ||
"@typescript-eslint/parser": "5.34.0", | ||
"@vitest/coverage-c8": "0.22.1", | ||
"c8": "7.12.0", | ||
"eslint": "8.22.0", | ||
"eslint-config-prettier": "8.5.0", | ||
"eslint-plugin-prettier": "4.2.1", | ||
"prettier": "2.7.1", | ||
"rimraf": "3.0.2", | ||
"rollup": "2.78.1", | ||
"rollup-plugin-dts": "4.2.2", | ||
"rollup-plugin-terser": "7.0.2", | ||
"tslib": "2.4.0", | ||
"typescript": "4.8.2", | ||
"vite": "3.0.9", | ||
"vitest": "0.22.1" | ||
}, | ||
"scripts": { | ||
"build": "rollup -c", | ||
"clean": "rimraf dist", | ||
"lint": "pnpm lint:eslint && pnpm lint:prettier", | ||
"lint:eslint": "eslint --ext .js,.ts src", | ||
"lint:prettier": "prettier --check --write .", | ||
"test": "jest -i" | ||
"test": "vitest --coverage" | ||
} | ||
} |
@@ -9,3 +9,6 @@ import { BASE64_CODE, BASE64_INDEX } from "./constant"; | ||
*/ | ||
export const encodeBase64 = (byteArray: number[], length: number): string => { | ||
export const encodeBase64 = ( | ||
byteArray: number[] | Buffer, | ||
length: number | ||
): string => { | ||
if (length <= 0 || length > byteArray.length) | ||
@@ -12,0 +15,0 @@ throw Error(`Illegal len: ${length}`); |
import { BCRYPT_SALT_LEN, GENSALT_DEFAULT_LOG2_ROUNDS } from "./constant"; | ||
import { encodeBase64 } from "./base64"; | ||
import { nextTick, random } from "./utils"; | ||
import { nextTick } from "./utils"; | ||
import { random } from "@random"; | ||
/** | ||
@@ -5,0 +7,0 @@ * Synchronously generates a salt. |
@@ -17,37 +17,2 @@ import { encodeUTF16toUTF8 } from "./utfx"; | ||
/** | ||
* Generates cryptographically secure random bytes. | ||
* | ||
* @param length Bytes length | ||
* @returns Random bytes | ||
* @throws {Error} If no random implementation is available | ||
*/ | ||
export const random = (length: number): number[] => { | ||
/* node */ if (typeof module !== "undefined" && module && module["exports"]) | ||
try { | ||
// eslint-disable-next-line | ||
return require("crypto")["randomBytes"](length); | ||
} catch (err) { | ||
// do nothing | ||
} | ||
/* WCA */ try { | ||
let array: Uint32Array; | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
(self["crypto"] || self["msCrypto"])["getRandomValues"]( | ||
(array = new Uint32Array(length)) | ||
); | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return | ||
return Array.prototype.slice.call(array); | ||
} catch (err) { | ||
// do nothing | ||
} | ||
throw Error( | ||
"Neither WebCryptoAPI nor a crypto module is available. Use bcrypt.setRandomFallback to set an alternative" | ||
); | ||
}; | ||
/** | ||
* Converts a JavaScript string to UTF8 bytes. | ||
@@ -54,0 +19,0 @@ * @param {string} str String |
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
213060
29
1573
20