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

@webcrypto/tools

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@webcrypto/tools - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0

7

CHANGELOG.md

@@ -0,1 +1,8 @@

# [1.2.0](https://github.com/willgm/web-crypto-tools/compare/v1.1.0...v1.2.0) (2020-10-26)
### Features
* **getCryptoObject:** method to get the crypto object depending on the environment ([bac4919](https://github.com/willgm/web-crypto-tools/commit/bac4919bd9f1f85c012f2267498972d00897172a))
# [1.1.0](https://github.com/willgm/web-crypto-tools/compare/v1.0.6...v1.1.0) (2020-05-29)

@@ -2,0 +9,0 @@

24

dist/lib/web-crypto-tools.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateHash = exports.decode = exports.encode = exports.generateRandomValues = exports.generateSalt = exports.generateNonce = exports.decryptValue = exports.encryptValue = exports.isTypedArray = exports.deriveCryptKey = exports.generateBaseCryptoKey = exports.PBKDF2_ITERATIONS_DEFAULT = void 0;
exports.generateHash = exports.decode = exports.encode = exports.generateRandomValues = exports.generateSalt = exports.generateNonce = exports.decryptValue = exports.encryptValue = exports.isTypedArray = exports.deriveCryptKey = exports.generateBaseCryptoKey = exports.getCryptoObject = exports.PBKDF2_ITERATIONS_DEFAULT = void 0;
/**

@@ -9,2 +9,12 @@ * Default number of iterations used with PBKDF2 algorithm

/**
* Returns the crypto object depending on browser support.
* IE11 has support for the Crypto API, but it is in a different global scope.
*
* @returns The Crypto object.
*/
function getCryptoObject() {
return window.crypto || window.msCrypto; // for IE 11
}
exports.getCryptoObject = getCryptoObject;
/**
* Creates a base Crypto Key from the original raw key, by default this base key

@@ -24,3 +34,3 @@ * should just be used to protect the original key to be discovery,

const isJwkKey = !isTypedArray(rawKey) && typeof rawKey === 'object';
return Promise.resolve(crypto.subtle.importKey(isJwkKey ? 'jwk' : format, typeof rawKey === 'string' ? encode(rawKey) : rawKey, algorithm, false, // the original value will not be extractable
return Promise.resolve(getCryptoObject().subtle.importKey(isJwkKey ? 'jwk' : format, typeof rawKey === 'string' ? encode(rawKey) : rawKey, algorithm, false, // the original value will not be extractable
keyUsages));

@@ -44,3 +54,3 @@ }

: algorithmForOrIterations;
return Promise.resolve(crypto.subtle.deriveKey(deriveAlgorithm, cryptoBaseKey, algorithmFor, false, // the original key will not be extractable
return Promise.resolve(getCryptoObject().subtle.deriveKey(deriveAlgorithm, cryptoBaseKey, algorithmFor, false, // the original key will not be extractable
keyUsages));

@@ -68,3 +78,3 @@ }

function encryptValue(data, cryptoKey, algorithm = { name: 'AES-GCM', iv: generateNonce() }) {
return Promise.resolve(crypto.subtle.encrypt(algorithm, cryptoKey, encode(data))).then(cryptoValue => [cryptoValue, algorithm.iv || null]);
return Promise.resolve(getCryptoObject().subtle.encrypt(algorithm, cryptoKey, encode(data))).then(cryptoValue => [cryptoValue, algorithm.iv || null]);
}

@@ -84,3 +94,3 @@ exports.encryptValue = encryptValue;

: nonceOrAlgorithm;
return Promise.resolve(crypto.subtle.decrypt(algorithm, cryptoKey, data));
return Promise.resolve(getCryptoObject().subtle.decrypt(algorithm, cryptoKey, data));
}

@@ -119,3 +129,3 @@ exports.decryptValue = decryptValue;

function generateRandomValues(byteSize = 8) {
return crypto.getRandomValues(new Uint8Array(byteSize));
return getCryptoObject().getRandomValues(new Uint8Array(byteSize));
}

@@ -153,5 +163,5 @@ exports.generateRandomValues = generateRandomValues;

function generateHash(data, algorithm = 'SHA-256') {
return Promise.resolve(crypto.subtle.digest(algorithm, encode(data)));
return Promise.resolve(getCryptoObject().subtle.digest(algorithm, encode(data)));
}
exports.generateHash = generateHash;
//# sourceMappingURL=web-crypto-tools.js.map

@@ -10,2 +10,11 @@ 'use strict';

/**
* Returns the crypto object depending on browser support.
* IE11 has support for the Crypto API, but it is in a different global scope.
*
* @returns The Crypto object.
*/
function getCryptoObject() {
return window.crypto || window.msCrypto; // for IE 11
}
/**
* Creates a base Crypto Key from the original raw key, by default this base key

@@ -28,3 +37,3 @@ * should just be used to protect the original key to be discovery,

var isJwkKey = !isTypedArray(rawKey) && typeof rawKey === 'object';
return Promise.resolve(crypto.subtle.importKey(isJwkKey ? 'jwk' : format, typeof rawKey === 'string' ? encode(rawKey) : rawKey, algorithm, false, // the original value will not be extractable
return Promise.resolve(getCryptoObject().subtle.importKey(isJwkKey ? 'jwk' : format, typeof rawKey === 'string' ? encode(rawKey) : rawKey, algorithm, false, // the original value will not be extractable
keyUsages));

@@ -49,3 +58,3 @@ }

: algorithmForOrIterations;
return Promise.resolve(crypto.subtle.deriveKey(deriveAlgorithm, cryptoBaseKey, algorithmFor, false, // the original key will not be extractable
return Promise.resolve(getCryptoObject().subtle.deriveKey(deriveAlgorithm, cryptoBaseKey, algorithmFor, false, // the original key will not be extractable
keyUsages));

@@ -72,3 +81,3 @@ }

if (algorithm === void 0) { algorithm = { name: 'AES-GCM', iv: generateNonce() }; }
return Promise.resolve(crypto.subtle.encrypt(algorithm, cryptoKey, encode(data))).then(function (cryptoValue) { return [cryptoValue, algorithm.iv || null]; });
return Promise.resolve(getCryptoObject().subtle.encrypt(algorithm, cryptoKey, encode(data))).then(function (cryptoValue) { return [cryptoValue, algorithm.iv || null]; });
}

@@ -87,3 +96,3 @@ /**

: nonceOrAlgorithm;
return Promise.resolve(crypto.subtle.decrypt(algorithm, cryptoKey, data));
return Promise.resolve(getCryptoObject().subtle.decrypt(algorithm, cryptoKey, data));
}

@@ -122,3 +131,3 @@ /**

if (byteSize === void 0) { byteSize = 8; }
return crypto.getRandomValues(new Uint8Array(byteSize));
return getCryptoObject().getRandomValues(new Uint8Array(byteSize));
}

@@ -154,6 +163,7 @@ /**

if (algorithm === void 0) { algorithm = 'SHA-256'; }
return Promise.resolve(crypto.subtle.digest(algorithm, encode(data)));
return Promise.resolve(getCryptoObject().subtle.digest(algorithm, encode(data)));
}
exports.PBKDF2_ITERATIONS_DEFAULT = PBKDF2_ITERATIONS_DEFAULT;
exports.getCryptoObject = getCryptoObject;
exports.generateBaseCryptoKey = generateBaseCryptoKey;

@@ -160,0 +170,0 @@ exports.deriveCryptKey = deriveCryptKey;

@@ -34,2 +34,19 @@ /**

/**
* @internal
*/
declare global {
/**
* IE11 use a different global property.
* @internal
*/
var msCrypto: Crypto;
}
/**
* Returns the crypto object depending on browser support.
* IE11 has support for the Crypto API, but it is in a different global scope.
*
* @returns The Crypto object.
*/
export declare function getCryptoObject(): Crypto;
/**
* Creates a base Crypto Key from the original raw key, by default this base key

@@ -36,0 +53,0 @@ * should just be used to protect the original key to be discovery,

@@ -6,2 +6,11 @@ /**

/**
* Returns the crypto object depending on browser support.
* IE11 has support for the Crypto API, but it is in a different global scope.
*
* @returns The Crypto object.
*/
function getCryptoObject() {
return window.crypto || window.msCrypto; // for IE 11
}
/**
* Creates a base Crypto Key from the original raw key, by default this base key

@@ -21,3 +30,3 @@ * should just be used to protect the original key to be discovery,

const isJwkKey = !isTypedArray(rawKey) && typeof rawKey === 'object';
return Promise.resolve(crypto.subtle.importKey(isJwkKey ? 'jwk' : format, typeof rawKey === 'string' ? encode(rawKey) : rawKey, algorithm, false, // the original value will not be extractable
return Promise.resolve(getCryptoObject().subtle.importKey(isJwkKey ? 'jwk' : format, typeof rawKey === 'string' ? encode(rawKey) : rawKey, algorithm, false, // the original value will not be extractable
keyUsages));

@@ -40,3 +49,3 @@ }

: algorithmForOrIterations;
return Promise.resolve(crypto.subtle.deriveKey(deriveAlgorithm, cryptoBaseKey, algorithmFor, false, // the original key will not be extractable
return Promise.resolve(getCryptoObject().subtle.deriveKey(deriveAlgorithm, cryptoBaseKey, algorithmFor, false, // the original key will not be extractable
keyUsages));

@@ -62,3 +71,3 @@ }

function encryptValue(data, cryptoKey, algorithm = { name: 'AES-GCM', iv: generateNonce() }) {
return Promise.resolve(crypto.subtle.encrypt(algorithm, cryptoKey, encode(data))).then(cryptoValue => [cryptoValue, algorithm.iv || null]);
return Promise.resolve(getCryptoObject().subtle.encrypt(algorithm, cryptoKey, encode(data))).then(cryptoValue => [cryptoValue, algorithm.iv || null]);
}

@@ -77,3 +86,3 @@ /**

: nonceOrAlgorithm;
return Promise.resolve(crypto.subtle.decrypt(algorithm, cryptoKey, data));
return Promise.resolve(getCryptoObject().subtle.decrypt(algorithm, cryptoKey, data));
}

@@ -109,3 +118,3 @@ /**

function generateRandomValues(byteSize = 8) {
return crypto.getRandomValues(new Uint8Array(byteSize));
return getCryptoObject().getRandomValues(new Uint8Array(byteSize));
}

@@ -140,6 +149,6 @@ /**

function generateHash(data, algorithm = 'SHA-256') {
return Promise.resolve(crypto.subtle.digest(algorithm, encode(data)));
return Promise.resolve(getCryptoObject().subtle.digest(algorithm, encode(data)));
}
export { PBKDF2_ITERATIONS_DEFAULT, generateBaseCryptoKey, deriveCryptKey, isTypedArray, encryptValue, decryptValue, generateNonce, generateSalt, generateRandomValues, encode, decode, generateHash };
export { PBKDF2_ITERATIONS_DEFAULT, getCryptoObject, generateBaseCryptoKey, deriveCryptKey, isTypedArray, encryptValue, decryptValue, generateNonce, generateSalt, generateRandomValues, encode, decode, generateHash };
//# sourceMappingURL=web-crypto-tools.es2015.js.map

@@ -6,2 +6,11 @@ /**

/**
* Returns the crypto object depending on browser support.
* IE11 has support for the Crypto API, but it is in a different global scope.
*
* @returns The Crypto object.
*/
function getCryptoObject() {
return window.crypto || window.msCrypto; // for IE 11
}
/**
* Creates a base Crypto Key from the original raw key, by default this base key

@@ -24,3 +33,3 @@ * should just be used to protect the original key to be discovery,

var isJwkKey = !isTypedArray(rawKey) && typeof rawKey === 'object';
return Promise.resolve(crypto.subtle.importKey(isJwkKey ? 'jwk' : format, typeof rawKey === 'string' ? encode(rawKey) : rawKey, algorithm, false, // the original value will not be extractable
return Promise.resolve(getCryptoObject().subtle.importKey(isJwkKey ? 'jwk' : format, typeof rawKey === 'string' ? encode(rawKey) : rawKey, algorithm, false, // the original value will not be extractable
keyUsages));

@@ -45,3 +54,3 @@ }

: algorithmForOrIterations;
return Promise.resolve(crypto.subtle.deriveKey(deriveAlgorithm, cryptoBaseKey, algorithmFor, false, // the original key will not be extractable
return Promise.resolve(getCryptoObject().subtle.deriveKey(deriveAlgorithm, cryptoBaseKey, algorithmFor, false, // the original key will not be extractable
keyUsages));

@@ -68,3 +77,3 @@ }

if (algorithm === void 0) { algorithm = { name: 'AES-GCM', iv: generateNonce() }; }
return Promise.resolve(crypto.subtle.encrypt(algorithm, cryptoKey, encode(data))).then(function (cryptoValue) { return [cryptoValue, algorithm.iv || null]; });
return Promise.resolve(getCryptoObject().subtle.encrypt(algorithm, cryptoKey, encode(data))).then(function (cryptoValue) { return [cryptoValue, algorithm.iv || null]; });
}

@@ -83,3 +92,3 @@ /**

: nonceOrAlgorithm;
return Promise.resolve(crypto.subtle.decrypt(algorithm, cryptoKey, data));
return Promise.resolve(getCryptoObject().subtle.decrypt(algorithm, cryptoKey, data));
}

@@ -118,3 +127,3 @@ /**

if (byteSize === void 0) { byteSize = 8; }
return crypto.getRandomValues(new Uint8Array(byteSize));
return getCryptoObject().getRandomValues(new Uint8Array(byteSize));
}

@@ -150,6 +159,6 @@ /**

if (algorithm === void 0) { algorithm = 'SHA-256'; }
return Promise.resolve(crypto.subtle.digest(algorithm, encode(data)));
return Promise.resolve(getCryptoObject().subtle.digest(algorithm, encode(data)));
}
export { PBKDF2_ITERATIONS_DEFAULT, generateBaseCryptoKey, deriveCryptKey, isTypedArray, encryptValue, decryptValue, generateNonce, generateSalt, generateRandomValues, encode, decode, generateHash };
export { PBKDF2_ITERATIONS_DEFAULT, getCryptoObject, generateBaseCryptoKey, deriveCryptKey, isTypedArray, encryptValue, decryptValue, generateNonce, generateSalt, generateRandomValues, encode, decode, generateHash };
//# sourceMappingURL=web-crypto-tools.module.js.map

@@ -12,2 +12,11 @@ (function (global, factory) {

/**
* Returns the crypto object depending on browser support.
* IE11 has support for the Crypto API, but it is in a different global scope.
*
* @returns The Crypto object.
*/
function getCryptoObject() {
return window.crypto || window.msCrypto; // for IE 11
}
/**
* Creates a base Crypto Key from the original raw key, by default this base key

@@ -30,3 +39,3 @@ * should just be used to protect the original key to be discovery,

var isJwkKey = !isTypedArray(rawKey) && typeof rawKey === 'object';
return Promise.resolve(crypto.subtle.importKey(isJwkKey ? 'jwk' : format, typeof rawKey === 'string' ? encode(rawKey) : rawKey, algorithm, false, // the original value will not be extractable
return Promise.resolve(getCryptoObject().subtle.importKey(isJwkKey ? 'jwk' : format, typeof rawKey === 'string' ? encode(rawKey) : rawKey, algorithm, false, // the original value will not be extractable
keyUsages));

@@ -51,3 +60,3 @@ }

: algorithmForOrIterations;
return Promise.resolve(crypto.subtle.deriveKey(deriveAlgorithm, cryptoBaseKey, algorithmFor, false, // the original key will not be extractable
return Promise.resolve(getCryptoObject().subtle.deriveKey(deriveAlgorithm, cryptoBaseKey, algorithmFor, false, // the original key will not be extractable
keyUsages));

@@ -74,3 +83,3 @@ }

if (algorithm === void 0) { algorithm = { name: 'AES-GCM', iv: generateNonce() }; }
return Promise.resolve(crypto.subtle.encrypt(algorithm, cryptoKey, encode(data))).then(function (cryptoValue) { return [cryptoValue, algorithm.iv || null]; });
return Promise.resolve(getCryptoObject().subtle.encrypt(algorithm, cryptoKey, encode(data))).then(function (cryptoValue) { return [cryptoValue, algorithm.iv || null]; });
}

@@ -89,3 +98,3 @@ /**

: nonceOrAlgorithm;
return Promise.resolve(crypto.subtle.decrypt(algorithm, cryptoKey, data));
return Promise.resolve(getCryptoObject().subtle.decrypt(algorithm, cryptoKey, data));
}

@@ -124,3 +133,3 @@ /**

if (byteSize === void 0) { byteSize = 8; }
return crypto.getRandomValues(new Uint8Array(byteSize));
return getCryptoObject().getRandomValues(new Uint8Array(byteSize));
}

@@ -156,6 +165,7 @@ /**

if (algorithm === void 0) { algorithm = 'SHA-256'; }
return Promise.resolve(crypto.subtle.digest(algorithm, encode(data)));
return Promise.resolve(getCryptoObject().subtle.digest(algorithm, encode(data)));
}
exports.PBKDF2_ITERATIONS_DEFAULT = PBKDF2_ITERATIONS_DEFAULT;
exports.getCryptoObject = getCryptoObject;
exports.generateBaseCryptoKey = generateBaseCryptoKey;

@@ -162,0 +172,0 @@ exports.deriveCryptKey = deriveCryptKey;

{
"name": "@webcrypto/tools",
"version": "1.1.0",
"version": "1.2.0",
"private": false,

@@ -100,22 +100,27 @@ "description": "A set of tools to facilitate and give good defaults for use of the native Web Crypto API.",

},
"husky": {
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
},
"devDependencies": {
"@commitlint/cli": "^8.3.5",
"@commitlint/config-conventional": "^8.3.4",
"@commitlint/cli": "^11.0.0",
"@commitlint/config-conventional": "^11.0.0",
"@semantic-release/changelog": "^5.0.1",
"@semantic-release/git": "^9.0.0",
"@types/jasmine": "^3.5.10",
"@types/node": "^12.12.42",
"@types/jasmine": "^3.6.0",
"@types/node": "^12.19.1",
"colors": "^1.3.2",
"commitizen": "^4.1.2",
"commitizen": "^4.2.2",
"coveralls": "^3.0.2",
"cross-env": "^5.2.0",
"cz-conventional-changelog": "^3.2.0",
"husky": "^1.0.1",
"jasmine-core": "^3.5.0",
"karma": "^5.0.9",
"cz-conventional-changelog": "^3.3.0",
"husky": "^4.3.0",
"jasmine-core": "^3.6.0",
"karma": "^5.2.3",
"karma-chrome-launcher": "^3.1.0",
"karma-cli": "^2.0.0",
"karma-jasmine": "^3.1.1",
"karma-jasmine": "^3.3.1",
"karma-mocha-reporter": "^2.2.5",
"karma-typescript": "^5.0.3",
"karma-typescript": "^5.2.0",
"lint-staged": "^8.0.0",

@@ -130,13 +135,13 @@ "lodash.camelcase": "^4.3.0",

"rollup-plugin-sourcemaps": "^0.4.2",
"rollup-plugin-typescript2": "^0.27.1",
"semantic-release": "^17.0.8",
"rollup-plugin-typescript2": "^0.27.3",
"semantic-release": "^17.2.1",
"shelljs": "^0.8.3",
"shx": "^0.3.2",
"ts-node": "^8.10.1",
"tslint": "^6.1.2",
"shx": "^0.3.3",
"ts-node": "^8.10.2",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0",
"tslint-config-standard": "^9.0.0",
"typedoc": "^0.17.7",
"typescript": "^3.0.3"
"typedoc": "^0.17.8",
"typescript": "^4.0.3"
}
}
# Web Crypto Tools
This project is a set of tools to facilitate and give good defaults for use of the native **[Web Crypto API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API)**.
<p>
<a
href="https://github.com/willgm/web-crypto-tools/actions"
target="_blank"
>
<img
alt="Build"
src="https://img.shields.io/github/workflow/status/willgm/web-crypto-tools/CI"
/>
</a>
<a
href="https://www.npmjs.com/package/@webcrypto/tools"
target="_blank"
>
<img
alt="Version"
src="https://img.shields.io/github/package-json/v/willgm/web-crypto-tools"
/>
</a>
<a
href="https://github.com/willgm/web-crypto-tools/blob/master/LICENSE"
target="_blank"
>
<img
src="https://img.shields.io/badge/license-MIT-blue.svg"
alt="web-crypto-tools is released under the MIT license"
/>
</a>
<a
href="https://github.com/willgm/web-crypto-tools/graphs/contributors"
target="_blank"
>
<img
alt="Contributors"
src="https://img.shields.io/github/contributors/willgm/web-crypto-tools.svg"
/>
</a>
</p>
> This project is a set of tools to facilitate and give good defaults for use of the native **[Web Crypto API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API)**.
This project depends on the browser implementation of [Crypto API](https://caniuse.com/#feat=cryptography) and [TextEncoder API](https://caniuse.com/#feat=textencoder), which are both current implemented on all green browsers. If you do need to support IE or any older browser, you should look for available polyfills.

@@ -11,5 +50,5 @@

## Usage
## :gear: Usage
### Install the project
### Install it at your project

@@ -51,3 +90,3 @@ ```bash

## Documentation
## :book: Documentation

@@ -54,0 +93,0 @@ The [documentation with all available API and options](https://willgm.github.io/web-crypto-tools/) at our GitHub Pages.

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

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