Socket
Socket
Sign inDemoInstall

@cosmjs/crypto

Package Overview
Dependencies
17
Maintainers
2
Versions
106
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.29.5 to 0.30.0-beta.1

8

build/pbkdf2.d.ts

@@ -8,6 +8,10 @@ /**

*/
export declare function getCryptoModule(): Promise<any | undefined>;
export declare function getNodeCrypto(): Promise<any | undefined>;
export declare function getSubtle(): Promise<any | undefined>;
export declare function pbkdf2Sha512Subtle(subtle: any, secret: Uint8Array, salt: Uint8Array, iterations: number, keylen: number): Promise<Uint8Array>;
export declare function pbkdf2Sha512Crypto(crypto: any, secret: Uint8Array, salt: Uint8Array, iterations: number, keylen: number): Promise<Uint8Array>;
/**
* Implements pbkdf2-sha512 using the Node.js crypro module (`import "crypto"`).
* This does not use subtle from [Crypto](https://developer.mozilla.org/en-US/docs/Web/API/Crypto).
*/
export declare function pbkdf2Sha512NodeCrypto(nodeCrypto: any, secret: Uint8Array, salt: Uint8Array, iterations: number, keylen: number): Promise<Uint8Array>;
export declare function pbkdf2Sha512Noble(secret: Uint8Array, salt: Uint8Array, iterations: number, keylen: number): Promise<Uint8Array>;

@@ -14,0 +18,0 @@ /**

@@ -26,3 +26,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.pbkdf2Sha512 = exports.pbkdf2Sha512Noble = exports.pbkdf2Sha512Crypto = exports.pbkdf2Sha512Subtle = exports.getSubtle = exports.getCryptoModule = void 0;
exports.pbkdf2Sha512 = exports.pbkdf2Sha512Noble = exports.pbkdf2Sha512NodeCrypto = exports.pbkdf2Sha512Subtle = exports.getSubtle = exports.getNodeCrypto = void 0;
const utils_1 = require("@cosmjs/utils");

@@ -38,17 +38,17 @@ const pbkdf2_1 = require("@noble/hashes/pbkdf2");

*/
async function getCryptoModule() {
async function getNodeCrypto() {
try {
const crypto = await Promise.resolve().then(() => __importStar(require("crypto")));
const nodeCrypto = await Promise.resolve().then(() => __importStar(require("crypto")));
// We get `Object{default: Object{}}` as a fallback when using
// `crypto: false` in Webpack 5, which we interprete as unavailable.
if (typeof crypto === "object" && Object.keys(crypto).length <= 1) {
if (typeof nodeCrypto === "object" && Object.keys(nodeCrypto).length <= 1) {
return undefined;
}
return crypto;
return nodeCrypto;
}
catch (_a) {
catch {
return undefined;
}
}
exports.getCryptoModule = getCryptoModule;
exports.getNodeCrypto = getNodeCrypto;
async function getSubtle() {

@@ -61,8 +61,7 @@ // From Node.js 15 onwards, webcrypto is available in globalThis.

// causes issues with bundlers and does not increase compatibility.
var _a, _b, _c;
// Browsers and Node.js 17+
let subtle = (_a = globalThis === null || globalThis === void 0 ? void 0 : globalThis.crypto) === null || _a === void 0 ? void 0 : _a.subtle;
let subtle = globalThis?.crypto?.subtle;
// Node.js 15+
if (!subtle)
subtle = (_c = (_b = globalThis === null || globalThis === void 0 ? void 0 : globalThis.crypto) === null || _b === void 0 ? void 0 : _b.webcrypto) === null || _c === void 0 ? void 0 : _c.subtle;
subtle = globalThis?.crypto?.webcrypto?.subtle;
return subtle;

@@ -88,10 +87,14 @@ }

exports.pbkdf2Sha512Subtle = pbkdf2Sha512Subtle;
async function pbkdf2Sha512Crypto(
/**
* Implements pbkdf2-sha512 using the Node.js crypro module (`import "crypto"`).
* This does not use subtle from [Crypto](https://developer.mozilla.org/en-US/docs/Web/API/Crypto).
*/
async function pbkdf2Sha512NodeCrypto(
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
crypto, secret, salt, iterations, keylen) {
(0, utils_1.assert)(crypto, "Argument crypto is falsy");
(0, utils_1.assert)(typeof crypto === "object", "Argument crypto is not of type object");
(0, utils_1.assert)(typeof crypto.pbkdf2 === "function", "crypto.pbkdf2 is not a function");
nodeCrypto, secret, salt, iterations, keylen) {
(0, utils_1.assert)(nodeCrypto, "Argument nodeCrypto is falsy");
(0, utils_1.assert)(typeof nodeCrypto === "object", "Argument nodeCrypto is not of type object");
(0, utils_1.assert)(typeof nodeCrypto.pbkdf2 === "function", "nodeCrypto.pbkdf2 is not a function");
return new Promise((resolve, reject) => {
crypto.pbkdf2(secret, salt, iterations, keylen, "sha512", (error, result) => {
nodeCrypto.pbkdf2(secret, salt, iterations, keylen, "sha512", (error, result) => {
if (error) {

@@ -106,3 +109,3 @@ reject(error);

}
exports.pbkdf2Sha512Crypto = pbkdf2Sha512Crypto;
exports.pbkdf2Sha512NodeCrypto = pbkdf2Sha512NodeCrypto;
async function pbkdf2Sha512Noble(secret, salt, iterations, keylen) {

@@ -121,5 +124,5 @@ return (0, pbkdf2_1.pbkdf2Async)(sha512_1.sha512, secret, salt, { c: iterations, dkLen: keylen });

else {
const crypto = await getCryptoModule();
if (crypto) {
return pbkdf2Sha512Crypto(crypto, secret, salt, iterations, keylen);
const nodeCrypto = await getNodeCrypto();
if (nodeCrypto) {
return pbkdf2Sha512NodeCrypto(nodeCrypto, secret, salt, iterations, keylen);
}

@@ -126,0 +129,0 @@ else {

@@ -16,3 +16,3 @@ "use strict";

}
catch (_a) {
catch {
try {

@@ -23,3 +23,3 @@ // eslint-disable-next-line @typescript-eslint/no-var-requires

}
catch (_b) {
catch {
throw new Error("No secure random number generator found");

@@ -26,0 +26,0 @@ }

{
"name": "@cosmjs/crypto",
"version": "0.29.5",
"version": "0.30.0-beta.1",
"description": "Cryptography resources for blockchain projects",

@@ -44,5 +44,5 @@ "contributors": [

"dependencies": {
"@cosmjs/encoding": "^0.29.5",
"@cosmjs/math": "^0.29.5",
"@cosmjs/utils": "^0.29.5",
"@cosmjs/encoding": "^0.30.0-beta.1",
"@cosmjs/math": "^0.30.0-beta.1",
"@cosmjs/utils": "^0.30.0-beta.1",
"@noble/hashes": "^1",

@@ -64,4 +64,4 @@ "bn.js": "^5.2.0",

"@types/node": "^15.0.1",
"@typescript-eslint/eslint-plugin": "^5.13.0",
"@typescript-eslint/parser": "^5.13.0",
"@typescript-eslint/eslint-plugin": "^5.54.0",
"@typescript-eslint/parser": "^5.54.0",
"buffer": "^6.0.3",

@@ -92,3 +92,4 @@ "eslint": "^7.5",

"webpack-cli": "^4.6.0"
}
},
"stableVersion": "0.29.5"
}

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc