-
-
Notifications
You must be signed in to change notification settings - Fork 46
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
Simple isomorphic wrapper ? #56
Comments
Hey Nicholas.
Not interested, because this (old node.js) approach is not tree-shaking friendly. We specifically use separate files to ensure sha256 code is not included if you're only using sha512, which helps to reduce bundle size. |
Fair.
How do you suggest handling this?
SImilar structure
@ns/misohashy/hash256 etc ?
?
|
import { sha256 } from "@noble/hashes/sha256";
import { sha512 } from "@noble/hashes/sha512";
import { sha3_256 } from "@noble/hashes/sha3";
function createHash(name) {
if (name === 'sha256') return sha256;
else if (name === 'sha512') return sha512;
else if (name === 'sha3_256') return sha3_256;
} |
I want something that doesn't require configuration for each bundler, and would support tree shaking, so it should just expose a browser impl via package.json. I'm not sure the state of "exports" these days in that regard, but potentially that. I was thinking more along the lines of:
It would be a thin wrapper around @noble/hashes/sha256 for browser and crypto.createHash for node Interface along these lines:
|
Yeah, separate files for each hash could work in this case. |
Turns out nodeResolution: Node16 is required for TS to honor it |
For things like ripple library where they are using createHash one needs to create little wrappers to replace existing functions, ala:
to replace:
This is annoying, and less than ideal because you have to mess with your webpack resolve.alias rather than rely upon a browser field in package.json.
I think a simple wrapper like this would go along way:
Are you interested in doing something like this under @noble/ ?
The text was updated successfully, but these errors were encountered: