.vscode | ||
test | ||
ts | ||
.gitignore | ||
.gitlab-ci.yml | ||
license | ||
npmextra.json | ||
package.json | ||
pnpm-lock.yaml | ||
readme.hints.md | ||
readme.md | ||
tsconfig.json |
@push.rocks/isohash
a hash package that works cross environment
Install
To start using @push.rocks/isohash in your project, you need to install it via npm. Ensure you have Node.js and npm installed on your system before proceeding. Then, run the following command in your project's root directory:
npm install @push.rocks/isohash --save
This will add @push.rocks/isohash
as a dependency to your package.json
file and download the package to the node_modules
folder.
Usage
This section provides detailed examples and explanations on how to use the @push.rocks/isohash
package effectively in your projects. The package offers a seamless way to compute hash values, specifically SHA-256, in various environments such as Node.js and modern web browsers.
Computing SHA-256 Hash
The primary feature of @push.rocks/isohash
is computing SHA-256 hash values from strings. This process varies depending on the environment—Node.js or the browser. The package abstracts these differences, providing a unified API.
TypeScript Example
Below is a TypeScript example demonstrating how to compute a SHA-256 hash from a given string. This example is applicable regardless of your environment, thanks to the cross-environment capabilities of @push.rocks/isohash.
First, ensure you have TypeScript and the necessary types installed in your project.
npm install typescript @types/node --save-dev
Then, you can compute a SHA-256 hash as follows:
import { sha256FromString } from '@push.rocks/isohash';
// Example string to hash
const exampleString = 'Hello, world!';
(async () => {
// Compute the SHA-256 hash of the example string
const hashResult = await sha256FromString(exampleString);
console.log(`SHA-256 Hash: ${hashResult}`);
})();
This function asynchronously returns the SHA-256 hash of the input string in hexadecimal format. The package internally handles the computation differences between Node.js and browser environments, providing a consistent API.
Understanding Cross-Environment Hashing
@push.rocks/isohash leverages different underlying technologies based on the execution environment:
- In Node.js, it uses the
crypto
module available in the Node.js standard library to compute hashes. - In Browsers, it utilizes the Web Crypto API (
crypto.subtle
).
This design choice ensures that the library is lightweight and performs well in both environments by using the most efficient and secure methods available in each.
Real-World Use Cases
Here are a few scenarios where computing hashes with @push.rocks/isohash can be beneficial:
- Verifying the integrity of data transmitted over a network.
- Generating unique identifiers for data that can be compared efficiently.
- Implementing secure password storage mechanisms (when combined with salts).
The cross-environment capability makes @push.rocks/isohash an excellent choice for applications that need to perform hashing operations both client-side and server-side, such as Single Page Applications (SPAs) with Node.js backends.
Contributions
Contributing to the development of @push.rocks/isohash
is encouraged. Whether you're improving the documentation, adding new features, or reporting bugs, your contributions are welcome. Visit the repository to get started.
Wrapping Up
In conclusion, @push.rocks/isohash
offers a streamlined, environment-agnostic approach to computing SHA-256 hash values in TypeScript projects. By abstracting away the environmental differences, it enables developers to write cleaner, more maintainable code for both server-side and client-side hashing needs.
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 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.