-
Notifications
You must be signed in to change notification settings - Fork 146
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
Support Web Crypto API to enable async hashing #123
Comments
AFAICT this library relies on Node’s |
@strogonoff I am not sure I follow, would something like this not work? The intention is to replace const str = "sdomaosdjasjdklasdkjhsdfjkhsdi23894u89weuriuhsduih8i9y893eyu8923hduhdjik3d";
const encode = new TextEncoder();
const digest = await webcrypto.subtle.digest('SHA-512', encode.encode(str));
return Buffer.from(digest).toString('hex'); |
@thernstig Ah yes. I was actually thinking along the same lines, that it’s possible to implement it in a way that works in both Node and browser. // web version
new Uint8Array(await crypto.subtle.digest('SHA-1', (new TextEncoder()).encode('…'))).toString()
// Node version
new Uint8Array(await require('crypto').webcrypto.subtle.digest('SHA-1', (new TextEncoder()).encode('…'))).toString() I saw that currently the library relies on Node’s flow, and I guess |
(Note that |
Yes. So the main gist of using the Web Crypto API is that it supports |
To me the reason for looking into this was not async but clearer and isomorphic logic. Currently there is browserify adding some unnecessary magic and increasing bundle size. Async is a nice bonus though. |
- Exposes subtle crypto as extra `subtle()` export - Uses subtle crypto behavior by default if no Node crypto is available (in which case main `hash()` export becomes an async function)
- Exposes subtle crypto as extra `subtle()` export - Uses subtle crypto behavior by default if no Node crypto is available (in which case main `hash()` export becomes an async function)
Are there any plans for this to be released? |
https://nodejs.org/api/webcrypto.html supports async hash functions. Meaning that if this libs implements an async function like:
Then users could use async functionality for this.
So the async version should be made clear to depend on Node.js and browsers supporting
globalThis.crypto
.The text was updated successfully, but these errors were encountered: