@pedrouid/iso-crypto
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -5,3 +5,2 @@ export declare function getBrowerCrypto(): Crypto; | ||
export declare function getOps(type: string): string[]; | ||
export declare function browserRandomBytes(length: number): Uint8Array; | ||
export declare function browserExportKey(cryptoKey: CryptoKey, type?: string): Promise<Uint8Array>; | ||
@@ -8,0 +7,0 @@ export declare function browserImportKey(buffer: Uint8Array, type?: string): Promise<CryptoKey>; |
@@ -12,5 +12,4 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.browserSha512 = exports.browserSha256 = exports.browserHmacSha512Sign = exports.browserHmacSha256Sign = exports.browserAesDecrypt = exports.browserAesEncrypt = exports.browserImportKey = exports.browserExportKey = exports.browserRandomBytes = exports.getOps = exports.getAlgo = exports.getSubtleCrypto = exports.getBrowerCrypto = void 0; | ||
exports.browserSha512 = exports.browserSha256 = exports.browserHmacSha512Sign = exports.browserHmacSha256Sign = exports.browserAesDecrypt = exports.browserAesEncrypt = exports.browserImportKey = exports.browserExportKey = exports.getOps = exports.getAlgo = exports.getSubtleCrypto = exports.getBrowerCrypto = void 0; | ||
const constants_1 = require("../constants"); | ||
const fallback_1 = require("./fallback"); | ||
function getBrowerCrypto() { | ||
@@ -40,10 +39,2 @@ return (global === null || global === void 0 ? void 0 : global.crypto) || (global === null || global === void 0 ? void 0 : global.msCrypto) || {}; | ||
exports.getOps = getOps; | ||
function browserRandomBytes(length) { | ||
const browserCrypto = getBrowerCrypto(); | ||
if (typeof browserCrypto.getRandomValues !== 'undefined') { | ||
return browserCrypto.getRandomValues(new Uint8Array(length)); | ||
} | ||
return fallback_1.fallbackRandomBytes(length); | ||
} | ||
exports.browserRandomBytes = browserRandomBytes; | ||
function browserExportKey(cryptoKey, type = constants_1.AES_BROWSER_ALGO) { | ||
@@ -50,0 +41,0 @@ return __awaiter(this, void 0, void 0, function* () { |
@@ -1,2 +0,1 @@ | ||
export declare function fallbackRandomBytes(length: number): Uint8Array; | ||
export declare function fallbackAesEncrypt(iv: Uint8Array, key: Uint8Array, data: Uint8Array): Uint8Array; | ||
@@ -3,0 +2,0 @@ export declare function fallbackAesDecrypt(iv: Uint8Array, key: Uint8Array, data: Uint8Array): Uint8Array; |
@@ -25,5 +25,4 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.fallbackRipemd160 = exports.fallbackSha512 = exports.fallbackSha256 = exports.fallbackHmacSha512Sign = exports.fallbackHmacSha256Sign = exports.fallbackAesDecrypt = exports.fallbackAesEncrypt = exports.fallbackRandomBytes = void 0; | ||
exports.fallbackRipemd160 = exports.fallbackSha512 = exports.fallbackSha256 = exports.fallbackHmacSha512Sign = exports.fallbackHmacSha256Sign = exports.fallbackAesDecrypt = exports.fallbackAesEncrypt = void 0; | ||
const aes_js_1 = __importDefault(require("aes-js")); | ||
const randombytes_1 = __importDefault(require("randombytes")); | ||
const hash = __importStar(require("hash.js")); | ||
@@ -33,6 +32,2 @@ const enc_utils_1 = require("enc-utils"); | ||
const index_1 = require("../index"); | ||
function fallbackRandomBytes(length) { | ||
return randombytes_1.default(length); | ||
} | ||
exports.fallbackRandomBytes = fallbackRandomBytes; | ||
function fallbackAesEncrypt(iv, key, data) { | ||
@@ -39,0 +34,0 @@ const aesCbc = new aes_js_1.default.ModeOfOperation.cbc(key, iv); |
@@ -1,2 +0,1 @@ | ||
export declare function nodeRandomBytes(length: number): Uint8Array; | ||
export declare function nodeAesEncrypt(iv: Uint8Array, key: Uint8Array, data: Uint8Array): Uint8Array; | ||
@@ -3,0 +2,0 @@ export declare function nodeAesDecrypt(iv: Uint8Array, key: Uint8Array, data: Uint8Array): Uint8Array; |
@@ -6,11 +6,6 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.nodeRipemd160 = exports.nodeSha512 = exports.nodeSha256 = exports.nodeHmacSha512Sign = exports.nodeHmacSha256Sign = exports.nodeAesDecrypt = exports.nodeAesEncrypt = exports.nodeRandomBytes = void 0; | ||
exports.nodeRipemd160 = exports.nodeSha512 = exports.nodeSha256 = exports.nodeHmacSha512Sign = exports.nodeHmacSha256Sign = exports.nodeAesDecrypt = exports.nodeAesEncrypt = void 0; | ||
const crypto_1 = __importDefault(require("crypto")); | ||
const enc_utils_1 = require("enc-utils"); | ||
const constants_1 = require("../constants"); | ||
function nodeRandomBytes(length) { | ||
const buf = crypto_1.default.randomBytes(length); | ||
return enc_utils_1.bufferToArray(buf); | ||
} | ||
exports.nodeRandomBytes = nodeRandomBytes; | ||
function nodeAesEncrypt(iv, key, data) { | ||
@@ -17,0 +12,0 @@ const cipher = crypto_1.default.createCipheriv(constants_1.AES_NODE_ALGO, key, iv); |
@@ -5,3 +5,2 @@ export declare function assert(condition: boolean, message: string): void; | ||
export declare function isConstantTime(arr1: Uint8Array, arr2: Uint8Array): boolean; | ||
export declare function isValidKeyLength(length: number): boolean; | ||
//# sourceMappingURL=validators.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isValidKeyLength = exports.isConstantTime = exports.isNode = exports.isBrowser = exports.assert = void 0; | ||
const constants_1 = require("./constants"); | ||
exports.isConstantTime = exports.isNode = exports.isBrowser = exports.assert = void 0; | ||
const env_1 = require("./env"); | ||
@@ -33,8 +32,2 @@ function assert(condition, message) { | ||
exports.isConstantTime = isConstantTime; | ||
function isValidKeyLength(length) { | ||
return !(length <= constants_1.LENGTH_0 || | ||
length > constants_1.MAX_KEY_LENGTH || | ||
parseInt(String(length)) !== length); | ||
} | ||
exports.isValidKeyLength = isValidKeyLength; | ||
//# sourceMappingURL=validators.js.map |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.randomBytes = void 0; | ||
const helpers_1 = require("../helpers"); | ||
const isoRandom = __importStar(require("@pedrouid/iso-random")); | ||
function randomBytes(length) { | ||
if (!helpers_1.isValidKeyLength(length)) { | ||
throw new Error(`randomBytes - invalid key length: ${length}`); | ||
} | ||
let result; | ||
if (helpers_1.isBrowser()) { | ||
result = helpers_1.browserRandomBytes(length); | ||
} | ||
else if (helpers_1.isNode()) { | ||
result = helpers_1.nodeRandomBytes(length); | ||
} | ||
else { | ||
result = helpers_1.fallbackRandomBytes(length); | ||
} | ||
return result; | ||
return isoRandom.randomBytes(length); | ||
} | ||
exports.randomBytes = randomBytes; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@pedrouid/iso-crypto", | ||
"description": "Isomorphic Cryptography Library for AES, HMAC and SHA2", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"author": "Pedro Gomes <github.com/pedrouid>", | ||
@@ -41,6 +41,6 @@ "license": "MIT", | ||
"dependencies": { | ||
"@pedrouid/iso-random": "^1.1.0", | ||
"aes-js": "^3.1.2", | ||
"enc-utils": "^3.0.0", | ||
"hash.js": "^1.1.7", | ||
"randombytes": "^2.1.0" | ||
"hash.js": "^1.1.7" | ||
}, | ||
@@ -52,3 +52,2 @@ "devDependencies": { | ||
"@types/node": "^14.14.7", | ||
"@types/randombytes": "^2.0.0", | ||
"husky": "^4.3.0", | ||
@@ -55,0 +54,0 @@ "tsdx": "^0.14.1", |
@@ -1,2 +0,2 @@ | ||
# iso-crypto [![npm version](https://badge.fury.io/js/iso-crypto.svg)](https://badge.fury.io/js/iso-crypto) | ||
# iso-crypto [![npm version](https://badge.fury.io/js/%40pedrouid%2Fiso-crypto.svg)](https://badge.fury.io/js/%40pedrouid%2Fiso-crypto) | ||
@@ -3,0 +3,0 @@ Isomorphic Cryptography Library for AES, HMAC and SHA2 |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 1 instance in 1 package
10
0
671584
2217
+ Added@pedrouid/iso-random@^1.1.0
+ Added@pedrouid/environment@1.0.1(transitive)
+ Added@pedrouid/iso-random@1.2.1(transitive)
- Removedrandombytes@^2.1.0