Skip to content

Commit

Permalink
Using node:crypto instead of external deps
Browse files Browse the repository at this point in the history
  • Loading branch information
wovalle committed Aug 2, 2024
1 parent 69fb31a commit dc8cea8
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 18 deletions.
4 changes: 0 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@
"src/**"
]
},
"dependencies": {
"js-md5": "^0.7.3",
"js-sha1": "^0.6.0"
},
"devDependencies": {
"eslint": "^8.23.0",
"jest": "^27.0.1"
Expand Down
7 changes: 3 additions & 4 deletions src/lib.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
var md5 = require('js-md5');
var sha1 = require('js-sha1');
var crypto = require('node:crypto');

/** List of hex digit for fast accessing by index */
var HEX_DIGITS = '0123456789abcdef'.split('');
Expand Down Expand Up @@ -72,7 +71,7 @@ var stringToCharBuffer = function (str) {
* @returns {Uint8Array} MD5 hash buffer
*/
var md5Hash = function (buf) {
return new Uint8Array(md5.arrayBuffer(buf));
return new Uint8Array(crypto.createHash('md5').update(buf).digest());
};

/**
Expand All @@ -81,7 +80,7 @@ var md5Hash = function (buf) {
* @returns {Uint8Array} SHA-1 hash buffer
*/
var sha1Hash = function (buf) {
return new Uint8Array(sha1.arrayBuffer(buf));
return new Uint8Array(crypto.createHash('sha1').update(buf).digest());
};

/**
Expand Down
10 changes: 0 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2063,16 +2063,6 @@ jest@^27.0.1:
import-local "^3.0.2"
jest-cli "^27.5.1"

js-md5@^0.7.3:
version "0.7.3"
resolved "https://registry.yarnpkg.com/js-md5/-/js-md5-0.7.3.tgz#b4f2fbb0b327455f598d6727e38ec272cd09c3f2"
integrity sha512-ZC41vPSTLKGwIRjqDh8DfXoCrdQIyBgspJVPXHBGu4nZlAEvG3nf+jO9avM9RmLiGakg7vz974ms99nEV0tmTQ==

js-sha1@^0.6.0:
version "0.6.0"
resolved "https://registry.yarnpkg.com/js-sha1/-/js-sha1-0.6.0.tgz#adbee10f0e8e18aa07cdea807cf08e9183dbc7f9"
integrity sha512-01gwBFreYydzmU9BmZxpVk6svJJHrVxEN3IOiGl6VO93bVKYETJ0sIth6DASI6mIFdt7NmfX9UiByRzsYHGU9w==

js-tokens@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
Expand Down

0 comments on commit dc8cea8

Please sign in to comment.