pax_global_header00006660000000000000000000000064147162177570014533gustar00rootroot0000000000000052 comment=6acbe74bad2c04cfc1d448a7ad385ffafa70b0aa createHash-1.3.0/000077500000000000000000000000001471621775700136035ustar00rootroot00000000000000createHash-1.3.0/.eslintrc000066400000000000000000000004751471621775700154350ustar00rootroot00000000000000{ "root": true, "extends": "@ljharb", "rules": { "func-style": "off", }, "overrides": [ { "files": "browser.js", "rules": { "global-require": "off", }, }, { "files": [ "browser.*.js", ], "rules": { "no-underscore-dangle": "warn", "sort-keys": "off", }, }, ], } createHash-1.3.0/.github/000077500000000000000000000000001471621775700151435ustar00rootroot00000000000000createHash-1.3.0/.github/FUNDING.yml000066400000000000000000000011061471621775700167560ustar00rootroot00000000000000# These are supported funding model platforms github: [ljharb] patreon: # Replace with a single Patreon username open_collective: # Replace with a single Open Collective username ko_fi: # Replace with a single Ko-fi username tidelift: npm/create-hash community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry liberapay: # Replace with a single Liberapay username issuehunt: # Replace with a single IssueHunt username otechie: # Replace with a single Otechie username custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] createHash-1.3.0/.github/workflows/000077500000000000000000000000001471621775700172005ustar00rootroot00000000000000createHash-1.3.0/.github/workflows/node-aught.yml000066400000000000000000000003271471621775700217600ustar00rootroot00000000000000name: 'Tests: node.js < 10' on: [pull_request, push] jobs: tests: uses: ljharb/actions/.github/workflows/node.yml@main with: range: '0.10 - 10' type: minors command: npm run tests-only createHash-1.3.0/.github/workflows/node-pretest.yml000066400000000000000000000002061471621775700223320ustar00rootroot00000000000000name: 'Tests: pretest/posttest' on: [pull_request, push] jobs: tests: uses: ljharb/actions/.github/workflows/pretest.yml@main createHash-1.3.0/.github/workflows/node-tens.yml000066400000000000000000000003721471621775700216210ustar00rootroot00000000000000name: 'Tests: node.js 10 - 20' on: [pull_request, push] permissions: contents: read jobs: tests: uses: ljharb/actions/.github/workflows/node.yml@main with: range: '>= 10 < 20' type: minors command: npm run tests-only createHash-1.3.0/.github/workflows/node-twenties.yml000066400000000000000000000003631471621775700225120ustar00rootroot00000000000000name: 'Tests: node.js >= 20' on: [pull_request, push] permissions: contents: read jobs: tests: uses: ljharb/actions/.github/workflows/node.yml@main with: range: '>= 20' type: minors command: npm run tests-only createHash-1.3.0/.github/workflows/rebase.yml000066400000000000000000000002571471621775700211700ustar00rootroot00000000000000name: Automatic Rebase on: [pull_request_target] jobs: _: uses: ljharb/actions/.github/workflows/rebase.yml@main secrets: token: ${{ secrets.GITHUB_TOKEN }} createHash-1.3.0/.github/workflows/require-allow-edits.yml000066400000000000000000000003031471621775700236150ustar00rootroot00000000000000name: Require “Allow Edits” on: [pull_request_target] jobs: _: name: "Require “Allow Edits”" runs-on: ubuntu-latest steps: - uses: ljharb/require-allow-edits@main createHash-1.3.0/.gitignore000066400000000000000000000001541471621775700155730ustar00rootroot00000000000000node_modules # Only apps should have lockfiles npm-shrinkwrap.json package-lock.json yarn.lock .npmignore createHash-1.3.0/.npmrc000066400000000000000000000000671471621775700147260ustar00rootroot00000000000000package-lock=false allow-same-version=true message=v%s createHash-1.3.0/CHANGELOG.md000066400000000000000000000152261471621775700154220ustar00rootroot00000000000000# Changelog All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [v1.3.0](https://github.com/browserify/createHash/compare/v1.2.0...v1.3.0) - 2024-11-16 ### Merged - 1.2.0 [`#23`](https://github.com/browserify/createHash/pull/23) ### Commits - [New] add a new noble-based implementation in modern browsers [`53fa3fa`](https://github.com/browserify/createHash/commit/53fa3fa277070eef0e326e9e153e932f40980d71) - [eslint] switch to eslint [`11f35f1`](https://github.com/browserify/createHash/commit/11f35f18aa8b521420e519c9e16f202d25a85ea4) - [meta] fix package.json indentation [`0bc497d`](https://github.com/browserify/createHash/commit/0bc497d7719852b6559721fbd6f6429f92f090fe) - [meta] add `auto-changelog` [`b85024a`](https://github.com/browserify/createHash/commit/b85024a40bc1c49111702305ebfcbdf827d84e2c) - [Tests] migrate from travis to GHA [`e65c363`](https://github.com/browserify/createHash/commit/e65c3633e0d3b40753ff61efb4d811a6d183e80a) - [meta] clean up scripts [`464a0a7`](https://github.com/browserify/createHash/commit/464a0a7f900405198522cdfbb4636a085523f0cf) - [meta] use `npmignore` [`597be5a`](https://github.com/browserify/createHash/commit/597be5a8e7f6b409407ac55bd23abada27dc2063) - [Deps] update `cipher-base`, `inherits`, `md5-js`, `ripemd160`, `sha.js` [`ebb6fe3`](https://github.com/browserify/createHash/commit/ebb6fe309473de33a6a7706a38f04bb60b97a7bb) - Only apps should have lockfiles [`86b273c`](https://github.com/browserify/createHash/commit/86b273c63bc2dd62a3865a60d1ca8da3e244ddc7) - [Dev Deps] add `safe-publish-latest` [`9643312`](https://github.com/browserify/createHash/commit/9643312fb93ff8067f8042fe332037a8e4f13f44) - [Deps] update `md5.js`, `safe-buffer` [`7cfa0da`](https://github.com/browserify/createHash/commit/7cfa0dac090b278129a6d4614114fe93c638f35e) - [Tests] move tests into `test` dir [`2c99d99`](https://github.com/browserify/createHash/commit/2c99d99ed40ab22ddd311f0482d07be4a6f0a6cb) - [Dev Deps] update `safe-buffer`, `tape` [`14b9a42`](https://github.com/browserify/createHash/commit/14b9a42a4e5520daa962ebf8c2747010e19440dc) - [meta] add `SECURITY.md` [`71e450a`](https://github.com/browserify/createHash/commit/71e450aa6448dff870e941c46768d09a83f5b31b) - [meta] add missing `engines.node` [`d334cfd`](https://github.com/browserify/createHash/commit/d334cfdab3243aecd0f01378eb997c524c35e0e6) - [Deps] pin `hash-base` to =3.0.3, due to a breaking change [`e7d0b88`](https://github.com/browserify/createHash/commit/e7d0b8878079bf7e565d7c35da81f535d9b5deed) - [Deps] remove mistakenly added dep [`abf9b29`](https://github.com/browserify/createHash/commit/abf9b2957cc6a6ebc510fc5a0c3edf4c3042bfc6) ## [v1.2.0](https://github.com/browserify/createHash/compare/v1.1.3...v1.2.0) - 2018-04-11 ### Merged - add back in md5.js file [`#22`](https://github.com/browserify/createHash/pull/22) ### Commits - md5: re-order for define-before-use [`1d56935`](https://github.com/browserify/createHash/commit/1d56935caf763b374be04811b7d1d47ae901f81c) - rm safe-buffer dependency, use md5.js and latest ripemd160 [`d71b31a`](https://github.com/browserify/createHash/commit/d71b31aae6524591e396be2a37638607250363e0) - README: cleanup [`c69f0b7`](https://github.com/browserify/createHash/commit/c69f0b7cef35e1a87040509e4a44dc3d4b44bdbd) - safe-buffer [`e6a6c05`](https://github.com/browserify/createHash/commit/e6a6c05d0d161dc72ef035a59a1ac32c2fc5fe62) - add MIT LICENSE [`7c45304`](https://github.com/browserify/createHash/commit/7c45304b789220a352c60f8b609273a120b76bf6) - travis: drop Node <4 [`482e5d9`](https://github.com/browserify/createHash/commit/482e5d9e43255b331eaf593ef70d46ef376e396c) - package: bump standard [`2612e83`](https://github.com/browserify/createHash/commit/2612e83e846787f46b14a2929c0c0bd4d92ef736) ## [v1.1.3](https://github.com/browserify/createHash/compare/v1.1.2...v1.1.3) - 2017-05-11 ### Merged - streaming ripemd [`#17`](https://github.com/browserify/createHash/pull/17) - travis: add node 5 and 6 [`#14`](https://github.com/browserify/createHash/pull/14) - clean up/rename the md5 stuff [`#9`](https://github.com/browserify/createHash/pull/9) ### Commits - adhere to standard [`c713c6a`](https://github.com/browserify/createHash/commit/c713c6aa345147594c63c8dddf7debf3a70b3b99) - lint it [`5a52062`](https://github.com/browserify/createHash/commit/5a52062e3b31eea2d0646c1e93912bd3b80e7ec1) - bump sha.js to 2.4.0 [`df0b846`](https://github.com/browserify/createHash/commit/df0b8461808ec3e7fb8a51bbaf5ba4e1e0472037) - rename file [`42550cd`](https://github.com/browserify/createHash/commit/42550cd167b60ba54e67a4be83ec8563aa3f0617) ## [v1.1.2](https://github.com/browserify/createHash/compare/1.1.1...v1.1.2) - 2015-09-28 ### Merged - normalize algs so ripemd160 works [`#6`](https://github.com/browserify/createHash/pull/6) - use cipher-base [`#5`](https://github.com/browserify/createHash/pull/5) ### Commits - update cipher-base [`a6eb6f7`](https://github.com/browserify/createHash/commit/a6eb6f782c1108e937cda7583b9a6d03312e076d) - adds .gitignore [`dcc25f9`](https://github.com/browserify/createHash/commit/dcc25f9e0b66d07fbf76d13e2616ea4c34cbcc90) ## [1.1.1](https://github.com/browserify/createHash/compare/v1.1.0...1.1.1) - 2015-03-18 ### Merged - avoid using stream when using update or digest methods [`#2`](https://github.com/browserify/createHash/pull/2) ### Commits - browser: consistent formatting [`98def75`](https://github.com/browserify/createHash/commit/98def752bb97a06184443b62b8e7cb8e3b0078de) - browser: cleanup [`82b3ba4`](https://github.com/browserify/createHash/commit/82b3ba43b709063aad884accbf9cd619ac1b3805) - typo [`776c1e9`](https://github.com/browserify/createHash/commit/776c1e96b3be86c82bb8dab1ee90c61a58edd89f) ## [v1.1.0](https://github.com/browserify/createHash/compare/v1.0.2...v1.1.0) - 2015-01-16 ### Commits - fix repo name, update readme, use browser.js as filename [`5ef8f19`](https://github.com/browserify/createHash/commit/5ef8f19b7cfbec433b6382080759195473f70fb2) ## [v1.0.2](https://github.com/browserify/createHash/compare/v1.0.1...v1.0.2) - 2015-01-14 ### Commits - use crypto in node [`f241b7d`](https://github.com/browserify/createHash/commit/f241b7dd04ba6e60326f0b1ea63bc172cfc5bf71) ## v1.0.1 - 2015-01-14 ### Commits - first [`b5c03ab`](https://github.com/browserify/createHash/commit/b5c03ab1d8f98ade1d746b4a72c7d92e2e26f681) - travis [`2cc3ae8`](https://github.com/browserify/createHash/commit/2cc3ae81f75634e1263e1fb643c734392edb7bf0) - update ripemd160 [`e2630b7`](https://github.com/browserify/createHash/commit/e2630b79b6a02d7f38e721a4f6a96b450bcbb8e8) createHash-1.3.0/LICENSE000066400000000000000000000021111471621775700146030ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2017 crypto-browserify contributors 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. createHash-1.3.0/README.md000066400000000000000000000012601471621775700150610ustar00rootroot00000000000000# create-hash [![Build Status](https://travis-ci.org/crypto-browserify/createHash.svg)](https://travis-ci.org/crypto-browserify/createHash) Node style hashes for use in the browser, with native hash functions in node. API is the same as hashes in node: ```js var createHash = require('create-hash') var hash = createHash('sha224') hash.update('synchronous write') // optional encoding parameter hash.digest() // synchronously get result with optional encoding parameter hash.write('write to it as a stream') hash.end() // remember it's a stream hash.read() // only if you ended it as a stream though ``` To get the JavaScript version even in node do `require('create-hash/browser')` createHash-1.3.0/SECURITY.md000066400000000000000000000002351471621775700153740ustar00rootroot00000000000000# Security Please email [@ljharb](https://github.com/ljharb) or see https://tidelift.com/security if you have a potential security vulnerability to report. createHash-1.3.0/browser.js000066400000000000000000000003531471621775700156250ustar00rootroot00000000000000'use strict'; if (typeof BigInt === 'undefined') { module.exports = require('./browser.old.js'); } else { try { module.exports = require('./browser.noble.js'); } catch (err) { module.exports = require('./browser.old.js'); } } createHash-1.3.0/browser.noble.js000066400000000000000000000033161471621775700167250ustar00rootroot00000000000000'use strict'; var sha1 = require('@noble/hashes/sha1'); var ripemd160 = require('@noble/hashes/ripemd160'); var sha2 = require('@noble/hashes/sha2'); var sha3 = require('@noble/hashes/sha3'); var blake2b = require('@noble/hashes/blake2b'); var blake2s = require('@noble/hashes/blake2s'); var inherits = require('inherits'); var MD5 = require('md5.js'); var Base = require('cipher-base'); var Buffer = require('safe-buffer').Buffer; function Hash(hash) { Base.call(this, 'digest'); this._hash = hash; } inherits(Hash, Base); Hash.prototype._update = function (data) { this._hash.update(data); }; Hash.prototype._final = function () { var uarr = this._hash.digest(); return Buffer.from(uarr.buffer, uarr.byteOffset, uarr.byteLength); }; var hashes = { // Supported by browser.old.js sha1: sha1.sha1, sha224: sha2.sha224, sha256: sha2.sha256, sha384: sha2.sha384, sha512: sha2.sha512, ripemd160: ripemd160.ripemd160, rmd160: ripemd160.ripemd160, // Not supported by browser.old.js (until sha.js updates?) 'sha512-224': sha2.sha512_224, // for browser.old.js: https://github.com/browserify/sha.js/pull/67 'sha512-256': sha2.sha512_256, // for browser.old.js: https://github.com/browserify/sha.js/pull/67 'sha3-224': sha3.sha3_224, 'sha3-256': sha3.sha3_256, 'sha3-384': sha3.sha3_384, 'sha3-512': sha3.sha3_512, blake2b512: blake2b.blake2b, // 512 is the default size blake2s256: blake2s.blake2s // 256 is the default size }; module.exports = function createHash(algorithm) { var alg = algorithm.toLowerCase(); if (alg === 'md5') { return new MD5(); } if (!Object.prototype.hasOwnProperty.call(hashes, alg)) { throw new Error('Digest method not supported'); } return new Hash(hashes[alg].create()); }; createHash-1.3.0/browser.old.js000066400000000000000000000012301471621775700163750ustar00rootroot00000000000000'use strict'; var inherits = require('inherits'); var MD5 = require('md5.js'); var RIPEMD160 = require('ripemd160'); var sha = require('sha.js'); var Base = require('cipher-base'); function Hash(hash) { Base.call(this, 'digest'); this._hash = hash; } inherits(Hash, Base); Hash.prototype._update = function (data) { this._hash.update(data); }; Hash.prototype._final = function () { return this._hash.digest(); }; module.exports = function createHash(algorithm) { var alg = algorithm.toLowerCase(); if (alg === 'md5') { return new MD5(); } if (alg === 'rmd160' || alg === 'ripemd160') { return new RIPEMD160(); } return new Hash(sha(alg)); }; createHash-1.3.0/index.js000066400000000000000000000000761471621775700152530ustar00rootroot00000000000000'use strict'; module.exports = require('crypto').createHash; createHash-1.3.0/md5.js000066400000000000000000000002001471621775700146160ustar00rootroot00000000000000'use strict'; var MD5 = require('md5.js'); module.exports = function (buffer) { return new MD5().update(buffer).digest(); }; createHash-1.3.0/package.json000066400000000000000000000035431471621775700160760ustar00rootroot00000000000000{ "name": "create-hash", "version": "1.3.0", "description": "create hashes for browserify", "browser": "browser.js", "main": "index.js", "scripts": { "prepack": "npmignore --auto --commentLines=autogenerated", "prepublishOnly": "safe-publish-latest", "prepublish": "not-in-publish || npm run prepublishOnly", "lint": "eslint --ext=js,mjs .", "pretest": "npm run lint", "test": "npm run tests-only", "tests-only": "tape 'test/**/*.js'", "posttest": "npx npm@'>=10.2' audit --production", "version": "auto-changelog && git add CHANGELOG.md", "postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\"" }, "repository": { "type": "git", "url": "git@github.com:crypto-browserify/createHash.git" }, "keywords": [ "crypto" ], "author": "", "license": "MIT", "bugs": { "url": "https://github.com/crypto-browserify/createHash/issues" }, "homepage": "https://github.com/crypto-browserify/createHash", "dependencies": { "cipher-base": "^1.0.4", "hash-base": "=3.0.3", "inherits": "^2.0.4", "md5.js": "^1.3.5", "readable-stream": "^2.3.8", "ripemd160": "^2.0.2", "safe-buffer": "^5.2.1", "sha.js": "^2.4.11" }, "optionalDependencies": { "@noble/hashes": "^1.3.3" }, "devDependencies": { "@ljharb/eslint-config": "^21.1.1", "auto-changelog": "^2.5.0", "encoding": "^0.1.13", "eslint": "=8.8.0", "hash-test-vectors": "^1.3.2", "in-publish": "^2.0.1", "npmignore": "^0.3.1", "safe-publish-latest": "^2.0.0", "tape": "^5.9.0" }, "publishConfig": { "ignore": [ ".github/workflows" ] }, "auto-changelog": { "output": "CHANGELOG.md", "template": "keepachangelog", "unreleased": false, "commitLimit": false, "backfillLimit": false, "hideCredit": true }, "engines": { "node": ">= 0.8" } } createHash-1.3.0/test/000077500000000000000000000000001471621775700145625ustar00rootroot00000000000000createHash-1.3.0/test/index.js000066400000000000000000000054601471621775700162340ustar00rootroot00000000000000'use strict'; var test = require('tape'); var Buffer = require('safe-buffer').Buffer; var algorithms = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160', 'ripemd160']; var encodings = ['hex', 'base64']; // ignore binary var vectors = require('hash-test-vectors'); vectors.forEach(function (vector) { // eslint-disable-next-line no-param-reassign vector.ripemd160 = vector.rmd160; }); var createHashOld = require('../browser.old.js'); var createHashAuto = require('../browser.js'); var implementations = [createHashOld]; if (createHashAuto !== createHashOld) { implementations.push(createHashAuto); } implementations.forEach(function (createHash) { algorithms.forEach(function (algorithm) { test('test ' + algorithm + ' against test vectors', function (t) { vectors.forEach(function (obj, i) { var input = Buffer.from(obj.input, 'base64'); var node = obj[algorithm]; var js = createHash(algorithm).update(input).digest('hex'); t.equal(js, node, algorithm + '(testVector[' + i + ']) == ' + node); }); encodings.forEach(function (encoding) { vectors.forEach(function (obj, i) { var input = Buffer.from(obj.input, 'base64').toString(encoding); var node = obj[algorithm]; var js = createHash(algorithm).update(input, encoding).digest('hex'); t.equal(js, node, algorithm + '(testVector[' + i + '], ' + encoding + ') == ' + node); }); }); vectors.forEach(function (obj, i) { var input = Buffer.from(obj.input, 'base64'); var node = obj[algorithm]; var hash = createHash(algorithm); hash.end(input); var js = hash.read().toString('hex'); t.equal(js, node, algorithm + '(testVector[' + i + ']) == ' + node); }); t.end(); }); }); }); var createHashNode = require('crypto').createHash; var randomBytes = require('crypto').randomBytes; function crossTest(createHashTest, createHashBase, algs) { var data = randomBytes(32); test('test against base implementation', function (t) { algs.forEach(function (algorithm) { var a = createHashTest(algorithm).update(data).digest('hex'); var b; try { b = createHashBase(algorithm).update(data).digest('hex'); } catch (err) {} var label = algorithm + '(' + data.toString('hex') + ')'; if (b) { t.equal(a, b, label); } else { t.skip(label); // Node.js version doesn't support it } }); t.end(); }); } var baseHashes = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'ripemd160', 'rmd160']; var extraHashes = ['sha512-224', 'sha512-256', 'sha3-224', 'sha3-256', 'sha3-384', 'sha3-512', 'blake2b512', 'blake2s256']; crossTest(createHashOld, createHashNode, baseHashes); // Only new version supports additional hashes if (createHashAuto !== createHashOld) { crossTest(createHashAuto, createHashNode, baseHashes); crossTest(createHashAuto, createHashNode, extraHashes); }