Socket
Socket
Sign inDemoInstall

webcrypto-core

Package Overview
Dependencies
Maintainers
2
Versions
78
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

webcrypto-core - npm Package Compare versions

Comparing version 1.0.16 to 1.0.17

87

build/webcrypto-core.es.js

@@ -29,10 +29,3 @@ /**

/**
* PEM converter
*/
class PemConverter {
/**
* Converts PEM to Array buffer
* @param pem PEM string
*/
static toArrayBuffer(pem) {

@@ -45,6 +38,2 @@ const base64 = pem

}
/**
* Converts PEM to Uint8Array
* @param pem PEM string
*/
static toUint8Array(pem) {

@@ -54,7 +43,2 @@ const bytes = this.toArrayBuffer(pem);

}
/**
* Converts buffer source to PEM
* @param buffer Buffer source
* @param tag PEM tag name
*/
static fromBufferSource(buffer, tag) {

@@ -80,14 +64,5 @@ const base64 = Convert.ToBase64(buffer);

}
/**
* Returns `true` if incoming data is PEM string, otherwise `false`
* @param data Data
*/
static isPEM(data) {
// tslint:disable-next-line:max-line-length
return /-----BEGIN .+-----[A-Za-z0-9+\/\+\=\s\n]+-----END .+-----/i.test(data);
}
/**
* Returns tag name from PEM string
* @param pem PEM string
*/
static getTagName(pem) {

@@ -103,7 +78,2 @@ if (!this.isPEM(pem)) {

}
/**
* Returns `true` if tag name from PEM matches to tagName parameter
* @param pem PEM string
* @param tagName Tag name for comparison
*/
static hasTagName(pem, tagName) {

@@ -132,3 +102,2 @@ const tag = this.getTagName(pem);

class ProviderCrypto {
//#region Digest
async digest(algorithm, data) {

@@ -144,4 +113,2 @@ this.checkDigest.apply(this, arguments);

}
//#endregion
//#region Generate key
async generateKey(algorithm, extractable, keyUsages) {

@@ -167,3 +134,2 @@ this.checkGenerateKey.apply(this, arguments);

checkGenerateKeyParams(algorithm) {
// nothing
}

@@ -173,4 +139,2 @@ async onGenerateKey(algorithm, extractable, keyUsages) {

}
//#endregion
//#region Sign
async sign(algorithm, key, data) {

@@ -188,4 +152,2 @@ this.checkSign.apply(this, arguments);

}
//#endregion
//#region Verify
async verify(algorithm, key, signature, data) {

@@ -203,4 +165,2 @@ this.checkVerify.apply(this, arguments);

}
//#endregion
//#region Encrypt
async encrypt(algorithm, key, data, options) {

@@ -218,4 +178,2 @@ this.checkEncrypt.apply(this, arguments);

}
//#endregion
//#region
async decrypt(algorithm, key, data, options) {

@@ -233,4 +191,2 @@ this.checkDecrypt.apply(this, arguments);

}
//#endregion
//#region Derive bits
async deriveBits(algorithm, baseKey, length, options) {

@@ -251,4 +207,2 @@ this.checkDeriveBits.apply(this, arguments);

}
//#endregion
//#region Export key
async exportKey(format, key) {

@@ -268,4 +222,2 @@ this.checkExportKey.apply(this, arguments);

}
//#endregion
//#region Import key
async importKey(format, keyData, algorithm, extractable, keyUsages) {

@@ -280,5 +232,3 @@ this.checkImportKey.apply(this, arguments);

this.checkImportParams(algorithm);
// check key usages
if (Array.isArray(this.usages)) {
// symmetric provider
this.checkKeyUsages(keyUsages, this.usages);

@@ -290,3 +240,2 @@ }

}
//#endregion
checkAlgorithmName(algorithm) {

@@ -298,6 +247,4 @@ if (algorithm.name.toLowerCase() !== this.name.toLowerCase()) {

checkAlgorithmParams(algorithm) {
// nothing
}
checkDerivedKeyParams(algorithm) {
// nothing
}

@@ -331,3 +278,2 @@ checkKeyUsages(usages, allowed) {

checkImportParams(algorithm) {
// nothing
}

@@ -365,3 +311,2 @@ checkKeyFormat(format) {

checkGenerateKeyParams(algorithm) {
// length
this.checkRequiredProperty(algorithm, "length");

@@ -426,3 +371,2 @@ if (typeof algorithm.length !== "number") {

checkAlgorithmParams(algorithm) {
// counter
this.checkRequiredProperty(algorithm, "counter");

@@ -435,3 +379,2 @@ if (!(algorithm.counter instanceof ArrayBuffer || ArrayBuffer.isView(algorithm.counter))) {

}
// length
this.checkRequiredProperty(algorithm, "length");

@@ -462,3 +405,2 @@ if (typeof algorithm.length !== "number") {

checkAlgorithmParams(algorithm) {
// iv
this.checkRequiredProperty(algorithm, "iv");

@@ -471,3 +413,2 @@ if (!(algorithm.iv instanceof ArrayBuffer || ArrayBuffer.isView(algorithm.iv))) {

}
// tagLength
if (!("tagLength" in algorithm)) {

@@ -516,3 +457,2 @@ algorithm.tagLength = 128;

checkGenerateKeyParams(algorithm) {
// length
this.checkRequiredProperty(algorithm, "length");

@@ -537,6 +477,4 @@ if (typeof algorithm.length !== "number") {

checkGenerateKeyParams(algorithm) {
// hash
this.checkRequiredProperty(algorithm, "hash");
this.checkHashAlgorithm(algorithm.hash, this.hashAlgorithms);
// public exponent
this.checkRequiredProperty(algorithm, "publicExponent");

@@ -550,3 +488,2 @@ if (!(algorithm.publicExponent && algorithm.publicExponent instanceof Uint8Array)) {

}
// modulus length
this.checkRequiredProperty(algorithm, "modulusLength");

@@ -609,3 +546,2 @@ switch (algorithm.modulusLength) {

checkAlgorithmParams(algorithm) {
// label
if (algorithm.label

@@ -620,3 +556,2 @@ && !(algorithm.label instanceof ArrayBuffer || ArrayBuffer.isView(algorithm.label))) {

checkGenerateKeyParams(algorithm) {
// named curve
this.checkRequiredProperty(algorithm, "namedCurve");

@@ -678,3 +613,2 @@ this.checkNamedCurve(algorithm.namedCurve);

checkAlgorithmParams(algorithm) {
// public
this.checkRequiredProperty(algorithm, "public");

@@ -700,6 +634,2 @@ if (!(algorithm.public instanceof CryptoKey)) {

}
/**
* Returns default size in bits by hash algorithm name
* @param algName Name of the hash algorithm
*/
getDefaultLength(algName) {

@@ -720,6 +650,4 @@ switch (algName.toUpperCase()) {

checkGenerateKeyParams(algorithm) {
// hash
this.checkRequiredProperty(algorithm, "hash");
this.checkHashAlgorithm(algorithm.hash, this.hashAlgorithms);
// length
if ("length" in algorithm) {

@@ -735,3 +663,2 @@ if (typeof algorithm.length !== "number") {

checkImportParams(algorithm) {
// hash
this.checkRequiredProperty(algorithm, "hash");

@@ -750,6 +677,4 @@ this.checkHashAlgorithm(algorithm.hash, this.hashAlgorithms);

checkAlgorithmParams(algorithm) {
// hash
this.checkRequiredProperty(algorithm, "hash");
this.checkHashAlgorithm(algorithm.hash, this.hashAlgorithms);
// salt
this.checkRequiredProperty(algorithm, "salt");

@@ -759,3 +684,2 @@ if (!(algorithm.salt instanceof ArrayBuffer || ArrayBuffer.isView(algorithm.salt))) {

}
// iterations
this.checkRequiredProperty(algorithm, "iterations");

@@ -772,3 +696,2 @@ if (typeof algorithm.iterations !== "number") {

if (extractable) {
// If extractable is not false, then throw a SyntaxError
throw new SyntaxError("extractable: Must be False");

@@ -787,6 +710,4 @@ }

checkAlgorithmParams(algorithm) {
// hash
this.checkRequiredProperty(algorithm, "hash");
this.checkHashAlgorithm(algorithm.hash, this.hashAlgorithms);
// salt
this.checkRequiredProperty(algorithm, "salt");

@@ -796,3 +717,2 @@ if (!BufferSourceConverter.isBufferSource(algorithm.salt)) {

}
// info
this.checkRequiredProperty(algorithm, "info");

@@ -806,3 +726,2 @@ if (!BufferSourceConverter.isBufferSource(algorithm.info)) {

if (extractable) {
// If extractable is not false, then throw a SyntaxError
throw new SyntaxError("extractable: Must be False");

@@ -920,7 +839,5 @@ }

this.checkRequiredArguments(arguments, 5, "deriveKey");
// check derivedKeyType
const preparedDerivedKeyType = this.prepareAlgorithm(derivedKeyType);
const importProvider = this.getProvider(preparedDerivedKeyType.name);
importProvider.checkDerivedKeyParams(preparedDerivedKeyType);
// derive bits
const preparedAlgorithm = this.prepareAlgorithm(algorithm);

@@ -930,3 +847,2 @@ const provider = this.getProvider(preparedAlgorithm.name);

const derivedBits = await provider.deriveBits({ ...preparedAlgorithm, name: provider.name }, baseKey, derivedKeyType.length, { keyUsage: false });
// import derived key
return this.importKey("raw", derivedBits, derivedKeyType, extractable, keyUsages);

@@ -962,3 +878,2 @@ }

}
// encrypt key data
const preparedAlgorithm = this.prepareAlgorithm(wrapAlgorithm);

@@ -970,3 +885,2 @@ const preparedData = BufferSourceConverter.toArrayBuffer(keyData);

async unwrapKey(format, wrappedKey, unwrappingKey, unwrapAlgorithm, unwrappedKeyAlgorithm, extractable, keyUsages) {
// decrypt wrapped key
const preparedAlgorithm = this.prepareAlgorithm(unwrapAlgorithm);

@@ -986,3 +900,2 @@ const preparedData = BufferSourceConverter.toArrayBuffer(wrappedKey);

}
// import key
return this.importKey(format, keyData, unwrappedKeyAlgorithm, extractable, keyUsages);

@@ -989,0 +902,0 @@ }

@@ -32,10 +32,3 @@ /**

/**
* PEM converter
*/
class PemConverter {
/**
* Converts PEM to Array buffer
* @param pem PEM string
*/
static toArrayBuffer(pem) {

@@ -48,6 +41,2 @@ const base64 = pem

}
/**
* Converts PEM to Uint8Array
* @param pem PEM string
*/
static toUint8Array(pem) {

@@ -57,7 +46,2 @@ const bytes = this.toArrayBuffer(pem);

}
/**
* Converts buffer source to PEM
* @param buffer Buffer source
* @param tag PEM tag name
*/
static fromBufferSource(buffer, tag) {

@@ -83,14 +67,5 @@ const base64 = pvtsutils.Convert.ToBase64(buffer);

}
/**
* Returns `true` if incoming data is PEM string, otherwise `false`
* @param data Data
*/
static isPEM(data) {
// tslint:disable-next-line:max-line-length
return /-----BEGIN .+-----[A-Za-z0-9+\/\+\=\s\n]+-----END .+-----/i.test(data);
}
/**
* Returns tag name from PEM string
* @param pem PEM string
*/
static getTagName(pem) {

@@ -106,7 +81,2 @@ if (!this.isPEM(pem)) {

}
/**
* Returns `true` if tag name from PEM matches to tagName parameter
* @param pem PEM string
* @param tagName Tag name for comparison
*/
static hasTagName(pem, tagName) {

@@ -135,3 +105,2 @@ const tag = this.getTagName(pem);

class ProviderCrypto {
//#region Digest
async digest(algorithm, data) {

@@ -147,4 +116,2 @@ this.checkDigest.apply(this, arguments);

}
//#endregion
//#region Generate key
async generateKey(algorithm, extractable, keyUsages) {

@@ -170,3 +137,2 @@ this.checkGenerateKey.apply(this, arguments);

checkGenerateKeyParams(algorithm) {
// nothing
}

@@ -176,4 +142,2 @@ async onGenerateKey(algorithm, extractable, keyUsages) {

}
//#endregion
//#region Sign
async sign(algorithm, key, data) {

@@ -191,4 +155,2 @@ this.checkSign.apply(this, arguments);

}
//#endregion
//#region Verify
async verify(algorithm, key, signature, data) {

@@ -206,4 +168,2 @@ this.checkVerify.apply(this, arguments);

}
//#endregion
//#region Encrypt
async encrypt(algorithm, key, data, options) {

@@ -221,4 +181,2 @@ this.checkEncrypt.apply(this, arguments);

}
//#endregion
//#region
async decrypt(algorithm, key, data, options) {

@@ -236,4 +194,2 @@ this.checkDecrypt.apply(this, arguments);

}
//#endregion
//#region Derive bits
async deriveBits(algorithm, baseKey, length, options) {

@@ -254,4 +210,2 @@ this.checkDeriveBits.apply(this, arguments);

}
//#endregion
//#region Export key
async exportKey(format, key) {

@@ -271,4 +225,2 @@ this.checkExportKey.apply(this, arguments);

}
//#endregion
//#region Import key
async importKey(format, keyData, algorithm, extractable, keyUsages) {

@@ -283,5 +235,3 @@ this.checkImportKey.apply(this, arguments);

this.checkImportParams(algorithm);
// check key usages
if (Array.isArray(this.usages)) {
// symmetric provider
this.checkKeyUsages(keyUsages, this.usages);

@@ -293,3 +243,2 @@ }

}
//#endregion
checkAlgorithmName(algorithm) {

@@ -301,6 +250,4 @@ if (algorithm.name.toLowerCase() !== this.name.toLowerCase()) {

checkAlgorithmParams(algorithm) {
// nothing
}
checkDerivedKeyParams(algorithm) {
// nothing
}

@@ -334,3 +281,2 @@ checkKeyUsages(usages, allowed) {

checkImportParams(algorithm) {
// nothing
}

@@ -368,3 +314,2 @@ checkKeyFormat(format) {

checkGenerateKeyParams(algorithm) {
// length
this.checkRequiredProperty(algorithm, "length");

@@ -429,3 +374,2 @@ if (typeof algorithm.length !== "number") {

checkAlgorithmParams(algorithm) {
// counter
this.checkRequiredProperty(algorithm, "counter");

@@ -438,3 +382,2 @@ if (!(algorithm.counter instanceof ArrayBuffer || ArrayBuffer.isView(algorithm.counter))) {

}
// length
this.checkRequiredProperty(algorithm, "length");

@@ -465,3 +408,2 @@ if (typeof algorithm.length !== "number") {

checkAlgorithmParams(algorithm) {
// iv
this.checkRequiredProperty(algorithm, "iv");

@@ -474,3 +416,2 @@ if (!(algorithm.iv instanceof ArrayBuffer || ArrayBuffer.isView(algorithm.iv))) {

}
// tagLength
if (!("tagLength" in algorithm)) {

@@ -519,3 +460,2 @@ algorithm.tagLength = 128;

checkGenerateKeyParams(algorithm) {
// length
this.checkRequiredProperty(algorithm, "length");

@@ -540,6 +480,4 @@ if (typeof algorithm.length !== "number") {

checkGenerateKeyParams(algorithm) {
// hash
this.checkRequiredProperty(algorithm, "hash");
this.checkHashAlgorithm(algorithm.hash, this.hashAlgorithms);
// public exponent
this.checkRequiredProperty(algorithm, "publicExponent");

@@ -553,3 +491,2 @@ if (!(algorithm.publicExponent && algorithm.publicExponent instanceof Uint8Array)) {

}
// modulus length
this.checkRequiredProperty(algorithm, "modulusLength");

@@ -612,3 +549,2 @@ switch (algorithm.modulusLength) {

checkAlgorithmParams(algorithm) {
// label
if (algorithm.label

@@ -623,3 +559,2 @@ && !(algorithm.label instanceof ArrayBuffer || ArrayBuffer.isView(algorithm.label))) {

checkGenerateKeyParams(algorithm) {
// named curve
this.checkRequiredProperty(algorithm, "namedCurve");

@@ -681,3 +616,2 @@ this.checkNamedCurve(algorithm.namedCurve);

checkAlgorithmParams(algorithm) {
// public
this.checkRequiredProperty(algorithm, "public");

@@ -703,6 +637,2 @@ if (!(algorithm.public instanceof CryptoKey)) {

}
/**
* Returns default size in bits by hash algorithm name
* @param algName Name of the hash algorithm
*/
getDefaultLength(algName) {

@@ -723,6 +653,4 @@ switch (algName.toUpperCase()) {

checkGenerateKeyParams(algorithm) {
// hash
this.checkRequiredProperty(algorithm, "hash");
this.checkHashAlgorithm(algorithm.hash, this.hashAlgorithms);
// length
if ("length" in algorithm) {

@@ -738,3 +666,2 @@ if (typeof algorithm.length !== "number") {

checkImportParams(algorithm) {
// hash
this.checkRequiredProperty(algorithm, "hash");

@@ -753,6 +680,4 @@ this.checkHashAlgorithm(algorithm.hash, this.hashAlgorithms);

checkAlgorithmParams(algorithm) {
// hash
this.checkRequiredProperty(algorithm, "hash");
this.checkHashAlgorithm(algorithm.hash, this.hashAlgorithms);
// salt
this.checkRequiredProperty(algorithm, "salt");

@@ -762,3 +687,2 @@ if (!(algorithm.salt instanceof ArrayBuffer || ArrayBuffer.isView(algorithm.salt))) {

}
// iterations
this.checkRequiredProperty(algorithm, "iterations");

@@ -775,3 +699,2 @@ if (typeof algorithm.iterations !== "number") {

if (extractable) {
// If extractable is not false, then throw a SyntaxError
throw new SyntaxError("extractable: Must be False");

@@ -790,6 +713,4 @@ }

checkAlgorithmParams(algorithm) {
// hash
this.checkRequiredProperty(algorithm, "hash");
this.checkHashAlgorithm(algorithm.hash, this.hashAlgorithms);
// salt
this.checkRequiredProperty(algorithm, "salt");

@@ -799,3 +720,2 @@ if (!pvtsutils.BufferSourceConverter.isBufferSource(algorithm.salt)) {

}
// info
this.checkRequiredProperty(algorithm, "info");

@@ -809,3 +729,2 @@ if (!pvtsutils.BufferSourceConverter.isBufferSource(algorithm.info)) {

if (extractable) {
// If extractable is not false, then throw a SyntaxError
throw new SyntaxError("extractable: Must be False");

@@ -923,7 +842,5 @@ }

this.checkRequiredArguments(arguments, 5, "deriveKey");
// check derivedKeyType
const preparedDerivedKeyType = this.prepareAlgorithm(derivedKeyType);
const importProvider = this.getProvider(preparedDerivedKeyType.name);
importProvider.checkDerivedKeyParams(preparedDerivedKeyType);
// derive bits
const preparedAlgorithm = this.prepareAlgorithm(algorithm);

@@ -933,3 +850,2 @@ const provider = this.getProvider(preparedAlgorithm.name);

const derivedBits = await provider.deriveBits({ ...preparedAlgorithm, name: provider.name }, baseKey, derivedKeyType.length, { keyUsage: false });
// import derived key
return this.importKey("raw", derivedBits, derivedKeyType, extractable, keyUsages);

@@ -965,3 +881,2 @@ }

}
// encrypt key data
const preparedAlgorithm = this.prepareAlgorithm(wrapAlgorithm);

@@ -973,3 +888,2 @@ const preparedData = pvtsutils.BufferSourceConverter.toArrayBuffer(keyData);

async unwrapKey(format, wrappedKey, unwrappingKey, unwrapAlgorithm, unwrappedKeyAlgorithm, extractable, keyUsages) {
// decrypt wrapped key
const preparedAlgorithm = this.prepareAlgorithm(unwrapAlgorithm);

@@ -989,3 +903,2 @@ const preparedData = pvtsutils.BufferSourceConverter.toArrayBuffer(wrappedKey);

}
// import key
return this.importKey(format, keyData, unwrappedKeyAlgorithm, extractable, keyUsages);

@@ -992,0 +905,0 @@ }

4

package.json
{
"name": "webcrypto-core",
"version": "1.0.16",
"version": "1.0.17",
"description": "Common layer to be used by crypto libraries based on WebCrypto API for input validation.",

@@ -44,3 +44,3 @@ "main": "build/webcrypto-core.js",

"dependencies": {
"pvtsutils": "^1.0.8",
"pvtsutils": "^1.0.9",
"tslib": "^1.10.0"

@@ -47,0 +47,0 @@ },

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