diff --git a/npmextra.json b/npmextra.json index 7f94df7..06be55b 100644 --- a/npmextra.json +++ b/npmextra.json @@ -5,15 +5,29 @@ "githost": "code.foss.global", "gitscope": "push.rocks", "gitrepo": "smarthash", - "description": "simplifies access to node hash functions", + "description": "Provides simplified access to Node.js hash functions, including SHA256 and MD5, with support for strings, streams, and files.", "npmPackagename": "@push.rocks/smarthash", - "license": "MIT" + "license": "MIT", + "keywords": [ + "crypto", + "hashing", + "SHA256", + "MD5", + "security", + "node.js", + "stream hashing", + "file hashing", + "synchronous hashing", + "asynchronous hashing", + "data integrity", + "typescript" + ] } }, "npmci": { "npmAccessLevel": "public" }, - "tsdocs": { + "tsdoc": { "legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n" } } \ No newline at end of file diff --git a/package.json b/package.json index e948270..a6535c6 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "@push.rocks/smarthash", "version": "3.0.4", "private": false, - "description": "simplified access to node hash functions", + "description": "Provides simplified access to Node.js hash functions, including SHA256 and MD5, with support for strings, streams, and files.", "main": "dist_ts/index.js", "typings": "dist_ts/index.d.ts", "scripts": { @@ -11,13 +11,18 @@ "buildDocs": "tsdoc" }, "keywords": [ - "pushrocks", - "typescript", - "hash", - "node", - "sha256", - "stream", - "filehash" + "crypto", + "hashing", + "SHA256", + "MD5", + "security", + "node.js", + "stream hashing", + "file hashing", + "synchronous hashing", + "asynchronous hashing", + "data integrity", + "typescript" ], "author": "Lossless GmbH", "license": "MIT", @@ -50,4 +55,4 @@ "last 1 chrome versions" ], "type": "module" -} +} \ No newline at end of file diff --git a/readme.hints.md b/readme.hints.md new file mode 100644 index 0000000..0519ecb --- /dev/null +++ b/readme.hints.md @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/readme.md b/readme.md index 44d23eb..dc31fbe 100644 --- a/readme.md +++ b/readme.md @@ -1,73 +1,135 @@ # @push.rocks/smarthash -simplifies access to node hash functions +simplified access to node hash functions -## Availabililty and Links -* [npmjs.org (npm package)](https://www.npmjs.com/package/@push.rocks/smarthash) -* [gitlab.com (source)](https://gitlab.com/push.rocks/smarthash) -* [github.com (source mirror)](https://github.com/push.rocks/smarthash) -* [docs (typedoc)](https://push.rocks.gitlab.io/smarthash/) +## Install +To install `@push.rocks/smarthash`, use the following command with npm: -## Status for master - -Status Category | Status Badge --- | -- -GitLab Pipelines | [![pipeline status](https://gitlab.com/push.rocks/smarthash/badges/master/pipeline.svg)](https://lossless.cloud) -GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/push.rocks/smarthash/badges/master/coverage.svg)](https://lossless.cloud) -npm | [![npm downloads per month](https://badgen.net/npm/dy/@push.rocks/smarthash)](https://lossless.cloud) -Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/push.rocks/smarthash)](https://lossless.cloud) -TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud) -node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/) -Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud) -PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@push.rocks/smarthash)](https://lossless.cloud) -PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@push.rocks/smarthash)](https://lossless.cloud) -BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@push.rocks/smarthash)](https://lossless.cloud) - -## Usage - -We recommend the use of TypeScript for best in class intellisense. - -```typescript -import * as smarthash from "smarthash"; - -// ====== -// sha265 -// ====== - -// from stream -let readStream = fs.createReadStream("./somefile.txt") -smarthash.sha256FromStream(readStream) - .then((resultString){ - console.log(resultString); // prints hash of the file - }); - -// from file -smarthash.sha256FromFile("./somefile.txt") - .then((resultString){ - console.log(resultString); // prints hash of the file - }); - -// from string -smarthash.sha256FromString("some weird random string") - .then((resultString){ - console.log(resultString); // prints hash of the file - }); - -let hashString = smarthash.sha256FromStringSync("some weird random string"); - -// === -// md5 -// === -smarthash.md5FromString('hellothere').then(md5String = { - // do something with it here -}) +```bash +npm install @push.rocks/smarthash --save ``` -## Contribution +This will add `@push.rocks/smarthash` to your project's dependencies. -We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :) +## Usage +The `@push.rocks/smarthash` library provides a simplified interface to Node.js hash functions, including utilities for hashing strings, files, and streams with popular algorithms like SHA-256 and MD5. Below are detailed examples to demonstrate the capabilities and usage of this library using ESM syntax and TypeScript. -For further information read the linked docs at the top of this readme. +### Hashing Strings +#### SHA-256 +```typescript +import { sha256FromString, sha256FromStringSync } from '@push.rocks/smarthash'; -## Legal -> MIT licensed | **©** [Task Venture Capital GmbH](https://task.vc) -| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy) +// Asynchronously hash a string +const asyncHash = async () => { + const hash = await sha256FromString('Hello, world!'); + console.log(hash); // Output the hashed string +}; +asyncHash(); + +// Synchronously hash a string +const syncHash = sha256FromStringSync('Hello, world!'); +console.log(syncHash); // Output the hashed string +``` + +#### MD5 +```typescript +import { md5FromString } from '@push.rocks/smarthash'; + +// Asynchronously hash a string with MD5 +const md5Hash = async () => { + const hash = await md5FromString('Hello, world!'); + console.log(hash); // Output the MD5 hash +}; +md5Hash(); +``` + +### Hashing Files +To hash a file, you can use the `sha256FromFile` function. It reads the file specified by the path and calculates the SHA-256 hash. +```typescript +import { sha256FromFile } from '@push.rocks/smarthash'; + +// Asynchronously hash a file +const hashFile = async () => { + const fileHash = await sha256FromFile('./path/to/your/file.txt'); + console.log(fileHash); // Output the file's hash +}; +hashFile(); +``` + +### Hashing Streams +`@push.rocks/smarthash` also allows for hashing of streams, which is particularly useful for large files or data streams. +```typescript +import { sha256FromStream } from '@push.rocks/smarthash'; +import fs from 'fs'; + +// Create a read stream from a file +const readStream = fs.createReadStream('./path/to/your/largeFile.txt'); + +// Asynchronously hash the stream +const hashStream = async () => { + const streamHash = await sha256FromStream(readStream); + console.log(streamHash); // Output the hash of the stream's content +}; +hashStream(); +``` + +### Advanced Usage +#### Hashing Objects +For hashing JavaScript objects, you can serialize them and hash the resulting string. This is useful for creating hashes from complex data structures. +```typescript +import { sha265FromObject } from '@push.rocks/smarthash'; + +// Hash a JavaScript object +const hashObject = async () => { + const object = { hello: 'world', number: 42 }; + const objectHash = await sha265FromObject(object); + console.log(objectHash); // Output the hash of the object +}; +hashObject(); +``` + +#### Error Handling +All asynchronous functions return promises, so you can use `.catch()` for error handling or try-catch blocks within async functions. +```typescript +import { sha256FromString } from '@push.rocks/smarthash'; + +// Using .catch() for promises +sha256FromString('test') + .then(hash => console.log(hash)) + .catch(error => console.error(error)); + +// Using try-catch with async functions +const getHash = async () => { + try { + const hash = await sha256FromString('test'); + console.log(hash); + } catch (error) { + console.error(error); + } +}; +getHash(); +``` + +### Best Practices +- Utilize asynchronous functions for hashing large files or streams to avoid blocking the main thread. +- For hashing sensitive information, ensure to follow security best practices, including using up-to-date algorithms and managing secrets properly. + +By leveraging `@push.rocks/smarthash`, developers can easily integrate hashing functionalities into their Node.js applications, benefiting from its simplified API and TypeScript support for better development experience. + +## License and Legal Information + +This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. + +**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file. + +### Trademarks + +This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH. + +### Company Information + +Task Venture Capital GmbH +Registered at District court Bremen HRB 35230 HB, Germany + +For any legal inquiries or if you require further information, please contact us via email at hello@task.vc. + +By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.