MCPcopy Index your code
hub / github.com/dchest/fast-sha256-js

github.com/dchest/fast-sha256-js @v1.1.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.1.0 ↗ · + Follow
50 symbols 137 edges 13 files 0 documented · 0%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

fast-sha256-js

SHA-256 implementation for JavaScript/TypeScript with typed arrays that works in modern browsers and Node.js. Implements the hash function, HMAC, and PBKDF2.

Public domain. No warranty.

Build Status

Installation

You can install fast-sha256-js via a package manager:

Bower:

$ bower install fast-sha256

NPM:

$ npm install fast-sha256

or download source code.

Usage

Functions accept and return Uint8Arrays. To convert strings, use external library (for example, nacl.util).

sha256(message)

Returns a SHA-256 hash of the message.

sha256.hmac(key, message)

Returns an HMAC-SHA-256 of the message for the key.

sha256.pbkdf2(password, salt, rounds, dkLen)

Returns a key of length dkLen derived using PBKDF2-HMAC-SHA256 from the given password, salt, and the number of rounds.

There are also classes Hash and HMAC:

new sha256.Hash()

Constructor for hash instance. Should be used with new. Available methods: update(), digest(), reset(), etc.

new sha256.HMAC(key)

Constructor for HMAC instance. Should be used with new. Available methods: update(), digest(), reset(), etc.

See comments in src/sha256.ts for details.

Usage with TypeScript

import sha256, { Hash, HMAC } from "fast-sha256";

sha256(data) // default export is hash

const h = new HMAC(key); // also Hash and HMAC classes
const mac = h.update(data).digest();

// alternatively:

import * as sha256 from "fast-sha256";

sha256.pbkdf2(password, salt, iterations, dkLen); // returns derived key
sha256.hash(data)

const hasher = new sha256.Hash();
hasher.update(data1);
hasher.update(data2);
const result = hasher.digest();

Testing and building

Install development dependencies:

$ npm install

Build JavaScript, minified version, and typings:

$ npm run build

Run tests:

$ npm test

Run tests on a different source file:

$ SHA256_SRC=sha256.min.js npm test

Run benchmark:

$ npm run bench

(or in a browser, open tests/bench.html).

Lint:

$ npm run lint

Notes

While this implementation is pretty fast compared to previous generation implementations, if you need an even faster one, check out asmCrypto.

Core symbols most depended-on inside this repo

update
called by 30
src/sha256.ts
hex
called by 22
test/test.js
finish
called by 21
src/sha256.ts
clean
called by 18
src/sha256.ts
dec
called by 17
test/test.js
digest
called by 14
src/sha256.ts
reset
called by 10
src/sha256.ts
_saveState
called by 6
src/sha256.ts

Shape

Function 28
Method 14
Class 8

Languages

TypeScript94%
Go6%

Modules by API surface

src/sha256.ts22 symbols
test/bench.js6 symbols
sha256.js6 symbols
sha256.d.ts4 symbols
test/test.js3 symbols
test/helpers.js3 symbols
sha256.min.js3 symbols
test/generate_data/sha256.go1 symbols
test/generate_data/pbkdf2.go1 symbols
test/generate_data/hmac.go1 symbols

For agents

$ claude mcp add fast-sha256-js \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page