Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional xxHash support and native SHA2-256 from browser Web Crypto API or Node.js crypto #15

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

mrauhu
Copy link

@mrauhu mrauhu commented Jul 15, 2022

Hello @pi0.

I created the useHash() function that supported the xxHash32 algorithm from hash-wasm or native SHA-256 (with fallback).

Resolves #14, differences:

  • for smaller base64 hashes (< 10 symbols) used xxHash32 (5.(3) unpadded bytes, 8 padded, max value — /////w==),
    instead of xxHash64 (10.(6) unpadded bytes, 12 padded, max value — //////////8=);
  • fallback to SHA2-256 if the hash-wasm package is not installed:
    • Web Crypto API global crypto variable (browser and Node.js);
    • Web Crypto API from crypto module (Node.js);
    • createHash() from crypto module (Node.js);
    • sha256base64().

From my point of view, best solution it's to change the hashed string max length from 10 to 11 bytes and use the xxHash64 algorithm instead.

Added tests for #11 issue for xxHash32 and SHA-256 algorithms.

Example of usage

import { useHash } from 'ohash';

const hash = await useHash();

const key = await hash(obj);

Best wishes,
Sergey.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve performance by using the xxHash64 algorithm from the hash-wasm package
1 participant