JSPM

@se-oss/sha256

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

Lightweight JavaScript utilities for SHA-256 and HMAC-SHA-256 hashing, compatible with any JS runtime.

Package Exports

  • @se-oss/sha256

Readme

@se-oss/sha256

CI NPM Version MIT License npm bundle size Install Size Edge Runtime Compatible

A JavaScript library that provides utilities for SHA-256 and HMAC-SHA-256 hashing. This library is designed to work seamlessly in any JavaScript runtime, offering efficient and straightforward functions for cryptographic hashing.


📦 Installation

npm i @se-oss/sha256
Install using your favorite package manager

pnpm

pnpm install @se-oss/sha256

yarn

yarn add @se-oss/sha256

📖 Usage

import { hmacSha256, sha256, timeSafeCompare } from '@se-oss/sha256';

// Hashing a string
const hash = sha256('Hello, world!');
console.log(hash);

// Hashing a Uint8Array
const data = new Uint8Array([1, 2, 3, 4, 5]);
const hash2 = sha256(data);
console.log(hash2);

// HMAC with a string key and message
const key = 'my-secret-key';
const message = 'Hello, HMAC!';
const hmac = hmacSha256(key, message);
console.log(hmac);

// HMAC with a Uint8Array key and message
const keyArray = new Uint8Array([1, 2, 3, 4, 5]);
const hmac2 = hmacSha256(keyArray, 'Hello, HMAC!');
console.log(hmac2);

const result = timeSafeCompare('hello', 'hello');
console.log(result); // true

const result2 = timeSafeCompare('hello', 'world');
console.log(result2); // false

📚 Documentation

For all configuration options, please see the API docs.

API
type BinaryLike = string | Uint8Array | Buffer;

function sha256(data: BinaryLike): Uint8Array;
function hmacSha256(key: BinaryLike, message: BinaryLike): Uint8Array;
function timeSafeCompare(a: string, b: string): boolean;

🤝 Contributing

Want to contribute? Awesome! To show your support is to star the project, or to raise issues on GitHub.

Thanks again for your support, it is much appreciated! 🙏

🙌 Credits

License

MIT © Shahrad Elahi and contributors.