Socket
Socket
Sign inDemoInstall

@toruslabs/eccrypto

Package Overview
Dependencies
Maintainers
5
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@toruslabs/eccrypto - npm Package Compare versions

Comparing version 5.0.0 to 5.0.1

78

dist/eccrypto.cjs.js

@@ -7,14 +7,2 @@ /******/ (() => { // webpackBootstrap

/************************************************************************/
/******/ /* webpack/runtime/compat get default export */
/******/ (() => {
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = (module) => {
/******/ var getter = module && module.__esModule ?
/******/ () => (module['default']) :
/******/ () => (module);
/******/ __webpack_require__.d(getter, { a: getter });
/******/ return getter;
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/define property getters */

@@ -32,14 +20,2 @@ /******/ (() => {

/******/
/******/ /* webpack/runtime/global */
/******/ (() => {
/******/ __webpack_require__.g = (function() {
/******/ if (typeof globalThis === 'object') return globalThis;
/******/ try {
/******/ return this || new Function('return this')();
/******/ } catch (e) {
/******/ if (typeof window === 'object') return window;
/******/ }
/******/ })();
/******/ })();
/******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */

@@ -80,5 +56,2 @@ /******/ (() => {

;// CONCATENATED MODULE: external "crypto"
const external_crypto_namespaceObject = require("crypto");
var external_crypto_default = /*#__PURE__*/__webpack_require__.n(external_crypto_namespaceObject);
;// CONCATENATED MODULE: external "elliptic"

@@ -88,6 +61,5 @@ const external_elliptic_namespaceObject = require("elliptic");

const ec = new external_elliptic_namespaceObject.ec("secp256k1");
// eslint-disable-next-line @typescript-eslint/no-explicit-any, n/no-unsupported-features/node-builtins
const browserCrypto = __webpack_require__.g.crypto || __webpack_require__.g.msCrypto || {};
const browserCrypto = globalThis.crypto || globalThis.msCrypto || {};
// eslint-disable-next-line @typescript-eslint/no-explicit-any

@@ -131,5 +103,2 @@ const subtle = browserCrypto.subtle || browserCrypto.webkitSubtle;

const arr = new Uint8Array(size);
if (typeof browserCrypto.getRandomValues === "undefined") {
return Buffer.from(external_crypto_default().randomBytes(size));
}
browserCrypto.getRandomValues(arr);

@@ -139,10 +108,5 @@ return Buffer.from(arr);

async function sha512(msg) {
if (subtle) {
const hash = await subtle.digest("SHA-512", msg);
const result = new Uint8Array(hash);
return result;
}
const hash = external_crypto_default().createHash("sha512");
const result = hash.update(msg).digest();
return new Uint8Array(result);
const hash = await subtle.digest("SHA-512", msg);
const result = new Uint8Array(hash);
return result;
}

@@ -162,12 +126,2 @@ function getAes(op) {

return Buffer.from(new Uint8Array(result));
} else if (op === "encrypt") {
const cipher = external_crypto_default().createCipheriv("aes-256-cbc", key, iv);
const firstChunk = cipher.update(data);
const secondChunk = cipher.final();
return Buffer.concat([firstChunk, secondChunk]);
} else if (op === "decrypt") {
const decipher = external_crypto_default().createDecipheriv("aes-256-cbc", key, iv);
const firstChunk = decipher.update(data);
const secondChunk = decipher.final();
return Buffer.concat([firstChunk, secondChunk]);
}

@@ -180,17 +134,11 @@ throw new Error(`Unsupported operation: ${op}`);

async function hmacSha256Sign(key, msg) {
if (subtle) {
const importAlgorithm = {
name: "HMAC",
hash: {
name: "SHA-256"
}
};
const cryptoKey = await subtle.importKey("raw", new Uint8Array(key), importAlgorithm, false, ["sign", "verify"]);
const sig = await subtle.sign("HMAC", cryptoKey, msg);
const result = Buffer.from(new Uint8Array(sig));
return result;
}
const hmac = external_crypto_default().createHmac("sha256", Buffer.from(key));
hmac.update(msg);
const result = hmac.digest();
const importAlgorithm = {
name: "HMAC",
hash: {
name: "SHA-256"
}
};
const cryptoKey = await subtle.importKey("raw", new Uint8Array(key), importAlgorithm, false, ["sign", "verify"]);
const sig = await subtle.sign("HMAC", cryptoKey, msg);
const result = Buffer.from(new Uint8Array(sig));
return result;

@@ -197,0 +145,0 @@ }

51

dist/eccrypto.esm.js

@@ -1,2 +0,1 @@

import nodeCrypto from 'crypto';
import { ec as ec$1 } from 'elliptic';

@@ -6,3 +5,3 @@

// eslint-disable-next-line @typescript-eslint/no-explicit-any, n/no-unsupported-features/node-builtins
const browserCrypto = global.crypto || global.msCrypto || {};
const browserCrypto = globalThis.crypto || globalThis.msCrypto || {};
// eslint-disable-next-line @typescript-eslint/no-explicit-any

@@ -46,5 +45,2 @@ const subtle = browserCrypto.subtle || browserCrypto.webkitSubtle;

const arr = new Uint8Array(size);
if (typeof browserCrypto.getRandomValues === "undefined") {
return Buffer.from(nodeCrypto.randomBytes(size));
}
browserCrypto.getRandomValues(arr);

@@ -54,10 +50,5 @@ return Buffer.from(arr);

async function sha512(msg) {
if (subtle) {
const hash = await subtle.digest("SHA-512", msg);
const result = new Uint8Array(hash);
return result;
}
const hash = nodeCrypto.createHash("sha512");
const result = hash.update(msg).digest();
return new Uint8Array(result);
const hash = await subtle.digest("SHA-512", msg);
const result = new Uint8Array(hash);
return result;
}

@@ -77,12 +68,2 @@ function getAes(op) {

return Buffer.from(new Uint8Array(result));
} else if (op === "encrypt") {
const cipher = nodeCrypto.createCipheriv("aes-256-cbc", key, iv);
const firstChunk = cipher.update(data);
const secondChunk = cipher.final();
return Buffer.concat([firstChunk, secondChunk]);
} else if (op === "decrypt") {
const decipher = nodeCrypto.createDecipheriv("aes-256-cbc", key, iv);
const firstChunk = decipher.update(data);
const secondChunk = decipher.final();
return Buffer.concat([firstChunk, secondChunk]);
}

@@ -95,17 +76,11 @@ throw new Error(`Unsupported operation: ${op}`);

async function hmacSha256Sign(key, msg) {
if (subtle) {
const importAlgorithm = {
name: "HMAC",
hash: {
name: "SHA-256"
}
};
const cryptoKey = await subtle.importKey("raw", new Uint8Array(key), importAlgorithm, false, ["sign", "verify"]);
const sig = await subtle.sign("HMAC", cryptoKey, msg);
const result = Buffer.from(new Uint8Array(sig));
return result;
}
const hmac = nodeCrypto.createHmac("sha256", Buffer.from(key));
hmac.update(msg);
const result = hmac.digest();
const importAlgorithm = {
name: "HMAC",
hash: {
name: "SHA-256"
}
};
const cryptoKey = await subtle.importKey("raw", new Uint8Array(key), importAlgorithm, false, ["sign", "verify"]);
const sig = await subtle.sign("HMAC", cryptoKey, msg);
const result = Buffer.from(new Uint8Array(sig));
return result;

@@ -112,0 +87,0 @@ }

'use strict';
var nodeCrypto = require('crypto');
var elliptic = require('elliptic');

@@ -8,3 +7,3 @@

// eslint-disable-next-line @typescript-eslint/no-explicit-any, n/no-unsupported-features/node-builtins
const browserCrypto = global.crypto || global.msCrypto || {};
const browserCrypto = globalThis.crypto || globalThis.msCrypto || {};
// eslint-disable-next-line @typescript-eslint/no-explicit-any

@@ -48,5 +47,2 @@ const subtle = browserCrypto.subtle || browserCrypto.webkitSubtle;

const arr = new Uint8Array(size);
if (typeof browserCrypto.getRandomValues === "undefined") {
return Buffer.from(nodeCrypto.randomBytes(size));
}
browserCrypto.getRandomValues(arr);

@@ -56,10 +52,5 @@ return Buffer.from(arr);

async function sha512(msg) {
if (subtle) {
const hash = await subtle.digest("SHA-512", msg);
const result = new Uint8Array(hash);
return result;
}
const hash = nodeCrypto.createHash("sha512");
const result = hash.update(msg).digest();
return new Uint8Array(result);
const hash = await subtle.digest("SHA-512", msg);
const result = new Uint8Array(hash);
return result;
}

@@ -79,12 +70,2 @@ function getAes(op) {

return Buffer.from(new Uint8Array(result));
} else if (op === "encrypt") {
const cipher = nodeCrypto.createCipheriv("aes-256-cbc", key, iv);
const firstChunk = cipher.update(data);
const secondChunk = cipher.final();
return Buffer.concat([firstChunk, secondChunk]);
} else if (op === "decrypt") {
const decipher = nodeCrypto.createDecipheriv("aes-256-cbc", key, iv);
const firstChunk = decipher.update(data);
const secondChunk = decipher.final();
return Buffer.concat([firstChunk, secondChunk]);
}

@@ -97,17 +78,11 @@ throw new Error(`Unsupported operation: ${op}`);

async function hmacSha256Sign(key, msg) {
if (subtle) {
const importAlgorithm = {
name: "HMAC",
hash: {
name: "SHA-256"
}
};
const cryptoKey = await subtle.importKey("raw", new Uint8Array(key), importAlgorithm, false, ["sign", "verify"]);
const sig = await subtle.sign("HMAC", cryptoKey, msg);
const result = Buffer.from(new Uint8Array(sig));
return result;
}
const hmac = nodeCrypto.createHmac("sha256", Buffer.from(key));
hmac.update(msg);
const result = hmac.digest();
const importAlgorithm = {
name: "HMAC",
hash: {
name: "SHA-256"
}
};
const cryptoKey = await subtle.importKey("raw", new Uint8Array(key), importAlgorithm, false, ["sign", "verify"]);
const sig = await subtle.sign("HMAC", cryptoKey, msg);
const result = Buffer.from(new Uint8Array(sig));
return result;

@@ -114,0 +89,0 @@ }

@@ -1,2 +0,1 @@

import nodeCrypto from 'crypto';
import { ec as ec$1 } from 'elliptic';

@@ -6,3 +5,3 @@

// eslint-disable-next-line @typescript-eslint/no-explicit-any, n/no-unsupported-features/node-builtins
const browserCrypto = global.crypto || global.msCrypto || {};
const browserCrypto = globalThis.crypto || globalThis.msCrypto || {};
// eslint-disable-next-line @typescript-eslint/no-explicit-any

@@ -46,5 +45,2 @@ const subtle = browserCrypto.subtle || browserCrypto.webkitSubtle;

const arr = new Uint8Array(size);
if (typeof browserCrypto.getRandomValues === "undefined") {
return Buffer.from(nodeCrypto.randomBytes(size));
}
browserCrypto.getRandomValues(arr);

@@ -54,10 +50,5 @@ return Buffer.from(arr);

async function sha512(msg) {
if (subtle) {
const hash = await subtle.digest("SHA-512", msg);
const result = new Uint8Array(hash);
return result;
}
const hash = nodeCrypto.createHash("sha512");
const result = hash.update(msg).digest();
return new Uint8Array(result);
const hash = await subtle.digest("SHA-512", msg);
const result = new Uint8Array(hash);
return result;
}

@@ -77,12 +68,2 @@ function getAes(op) {

return Buffer.from(new Uint8Array(result));
} else if (op === "encrypt") {
const cipher = nodeCrypto.createCipheriv("aes-256-cbc", key, iv);
const firstChunk = cipher.update(data);
const secondChunk = cipher.final();
return Buffer.concat([firstChunk, secondChunk]);
} else if (op === "decrypt") {
const decipher = nodeCrypto.createDecipheriv("aes-256-cbc", key, iv);
const firstChunk = decipher.update(data);
const secondChunk = decipher.final();
return Buffer.concat([firstChunk, secondChunk]);
}

@@ -95,17 +76,11 @@ throw new Error(`Unsupported operation: ${op}`);

async function hmacSha256Sign(key, msg) {
if (subtle) {
const importAlgorithm = {
name: "HMAC",
hash: {
name: "SHA-256"
}
};
const cryptoKey = await subtle.importKey("raw", new Uint8Array(key), importAlgorithm, false, ["sign", "verify"]);
const sig = await subtle.sign("HMAC", cryptoKey, msg);
const result = Buffer.from(new Uint8Array(sig));
return result;
}
const hmac = nodeCrypto.createHmac("sha256", Buffer.from(key));
hmac.update(msg);
const result = hmac.digest();
const importAlgorithm = {
name: "HMAC",
hash: {
name: "SHA-256"
}
};
const cryptoKey = await subtle.importKey("raw", new Uint8Array(key), importAlgorithm, false, ["sign", "verify"]);
const sig = await subtle.sign("HMAC", cryptoKey, msg);
const result = Buffer.from(new Uint8Array(sig));
return result;

@@ -112,0 +87,0 @@ }

{
"name": "@toruslabs/eccrypto",
"version": "5.0.0",
"version": "5.0.1",
"description": "JavaScript Elliptic curve cryptography library, includes fix to browser.js so that encrypt/decrypt works",

@@ -5,0 +5,0 @@ "main": "./dist/lib.cjs/index.js",

Sorry, the diff of this file is too big to display

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