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

crypto-hash

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

crypto-hash - npm Package Compare versions

Comparing version 2.0.1 to 3.0.0

8

index.d.ts

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

export interface OptionsHexOutput {
export type OptionsHexOutput = {
outputFormat?: 'hex';
}
};
export interface OptionBufferOutput {
export type OptionBufferOutput = {
outputFormat: 'buffer';
}
};

@@ -9,0 +9,0 @@ /**

@@ -5,51 +5,51 @@ import {Buffer} from 'node:buffer';

const threadFilePath = new URL('thread.js', import.meta.url);
let create = algorithm => async (buffer, {outputFormat = 'hex'} = {}) => {
const hash = crypto.createHash(algorithm);
hash.update(buffer, typeof buffer === 'string' ? 'utf8' : undefined);
let worker; // Lazy
let taskIdCounter = 0;
const tasks = new Map();
if (outputFormat === 'hex') {
return hash.digest('hex');
}
const createWorker = () => {
worker = new Worker(threadFilePath);
return hash.digest().buffer;
};
worker.on('message', message => {
const task = tasks.get(message.id);
tasks.delete(message.id);
if (tasks.size === 0) {
worker.unref();
}
if (Worker !== undefined) {
const threadFilePath = new URL('thread.js', import.meta.url);
task(message.value);
});
let worker; // Lazy
let taskIdCounter = 0;
const tasks = new Map();
worker.on('error', error => {
// Any error here is effectively an equivalent of segfault and have no scope, so we just throw it on callback level
throw error;
});
};
const createWorker = () => {
worker = new Worker(threadFilePath);
const taskWorker = (value, transferList) => new Promise(resolve => {
const id = taskIdCounter++;
tasks.set(id, resolve);
worker.on('message', message => {
const task = tasks.get(message.id);
tasks.delete(message.id);
if (tasks.size === 0) {
worker.unref();
}
if (worker === undefined) {
createWorker();
}
task(message.value);
});
worker.ref();
worker.postMessage({id, value}, transferList);
});
worker.on('error', error => {
// Any error here is effectively an equivalent of segfault and have no scope, so we just throw it on callback level
throw error;
});
};
let create = algorithm => async (buffer, {outputFormat = 'hex'} = {}) => {
const hash = crypto.createHash(algorithm);
hash.update(buffer, typeof buffer === 'string' ? 'utf8' : undefined);
const taskWorker = (value, transferList) => new Promise(resolve => {
const id = taskIdCounter++;
tasks.set(id, resolve);
if (outputFormat === 'hex') {
return hash.digest('hex');
}
if (worker === undefined) {
createWorker();
}
return hash.digest().buffer;
};
worker.ref();
worker.postMessage({id, value}, transferList);
});
if (Worker !== undefined) {
create = algorithm => async (source, {outputFormat = 'hex'} = {}) => {

@@ -56,0 +56,0 @@ let buffer;

{
"name": "crypto-hash",
"version": "2.0.1",
"version": "3.0.0",
"description": "Tiny hashing module that uses the native crypto API in Node.js and the browser",

@@ -15,2 +15,3 @@ "license": "MIT",

"exports": {
"types": "./index.d.ts",
"node": "./index.js",

@@ -20,6 +21,7 @@ "default": "./browser.js"

"engines": {
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
"node": ">=18"
},
"scripts": {
"test": "xo && ava test.js && karmatic test-browser.js && tsd"
"//test": "xo && ava test.js && karmatic test-browser.js && tsd",
"test": "xo && ava test.js && tsd"
},

@@ -30,3 +32,2 @@ "files": [

"browser.js",
"browser.d.ts",
"thread.js"

@@ -48,9 +49,8 @@ ],

"devDependencies": {
"@sindresorhus/is": "^4.2.0",
"ava": "^3.15.0",
"@sindresorhus/is": "^6.0.1",
"ava": "^5.3.1",
"hash.js": "^1.1.7",
"karmatic": "2.1.0",
"tsd": "^0.18.0",
"xo": "^0.45.0"
"tsd": "^0.29.0",
"xo": "^0.56.0"
}
}

@@ -7,3 +7,3 @@ # crypto-hash

In Node.js it uses [`require('crypto')`](https://nodejs.org/api/crypto.html#crypto_class_hash), while in the browser it uses [`window.crypto`](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest).
In Node.js it uses [`node:crypto`](https://nodejs.org/api/crypto.html#crypto_class_hash), while in the browser it uses [`window.crypto`](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest).

@@ -14,3 +14,3 @@ The browser version is only ~300 bytes minified & gzipped.

This package is for modern browsers. IE11 is not supported.
This package is for modern browsers. Internet Explorer is not supported.

@@ -29,3 +29,3 @@ ## Install

console.log(await sha256('🦄'));
//=> '5df82936cbf0864be4b7ba801bee392457fde9e4'
//=> '36bf255468003165652fe978eaaa8898e191664028475f83f506dabd95298efc'
```

@@ -32,0 +32,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