JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3481
  • Score
    100M100P100Q123731F
  • License MIT

Fast SHA-1 digest hash based on Uint8Array, pure JavaScript.

Package Exports

  • sha1-uint8array

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (sha1-uint8array) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

sha1-uint8array

Node.js CI npm version

Fast SHA-1 digest hash based on Uint8Array, pure JavaScript.

SYNOPSIS

const createHash = require("sha1-uint8array").createHash;

const text = "";
const hex = createHash().update(text).digest("hex");
// => "da39a3ee5e6b4b0d3255bfef95601890afd80709"

const data = new Uint8Array(0);
const hash = createHash().update(data).digest();
// => <Uint8Array da 39 a3 ee 5e 6b 4b 0d 32 55 bf ef 95 60 18 90 af d8 07 09>

The interface is a subset of Node.js's crypto module. See TypeScript declaration sha1-uint8array.d.ts for detail.

BENCHMARK

Node.js's native crypto module run faster than others on Node.js. sha1-uint8array runs well both on Node.js and browsers with its smaller footprint.

module version node.js V14 Chrome 87 Safari 14 minified backend note
crypto - 76m 👍s - - - OpenSSL 👍 on node.js
sha1-uint8array 0.8.0 233ms 362ms 👍 210ms 👍 2KB 👍 Uint8Array 👍 on browsers
hash.js 1.1.7 514ms 592ms 936ms 7KB Array hash.js/lib/hash/sha/1.js
jssha 3.2.0 713ms 824ms 777ms 9KB Uint8Array jssha/dist/sha1.js
crypto-js 4.0.0 790ms 868ms 1006ms 108KB Uint8Array crypto-js/sha1.js
jshashes 1.0.8 697ms 1590ms 851ms 23KB Array jshashes/hashes.js
tiny-sha1 0.2.1 193ms 534ms 2548ms 2KB Uint8Array tiny-sha1/dist/tiny-sha1.js
sha.js 2.4.11 354ms 698ms 3629ms 26KB Buffer sha.js/sha1.js
create-hash 1.2.0 433ms 745ms 3686ms 97KB Buffer create-hash/browser.js

The benchmark result above is tested on macOS 10.15.7 Intel Core i7 3.2GHz. You could run the benchmark as below.

git clone https://github.com/kawanet/sha1-uint8array.git
npm install
npm run build

# run the benchmark on Node.js
REPEAT=10000 ./node_modules/.bin/mocha test/99.benchmark.js

# run tests and the benchmark on browser
make -C browser
open browser/test.html

BROWSER

<script src="https://cdn.jsdelivr.net/npm/sha1-uint8array/dist/sha1-uint8array.min.js"></script>
<script>
    const text = "";
    const hex = createHash().update(text).digest("hex");
    // => "da39a3ee5e6b4b0d3255bfef95601890afd80709"
    
    const data = new Uint8Array(0);
    const hash = createHash().update(data).digest();
    // => <Uint8Array da 39 a3 ee 5e 6b 4b 0d 32 55 bf ef 95 60 18 90 af d8 07 09>
</script>

MIT LICENSE

Copyright (c) 2020-2021 Yusuke Kawasaki

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.