@toruslabs/eccrypto
Advanced tools
Comparing version 5.0.0 to 5.0.1
@@ -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 @@ } |
@@ -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
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses eval() which is a dangerous function. This prevents the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
0
211652
968