-
Notifications
You must be signed in to change notification settings - Fork 514
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
Swap create-hash for hash.js sha256 #2186
Conversation
@mankins The issue is this: browserify/cipher-base#11 So changing to a package that works well in the browser is a great solution. |
Also it seems like you probably need to add the polyfill for In webpack that would look like:
These polyfills are typically used by other libraries as well, such as web3.js |
You mean on my app, right? I haven't needed that yet, but good to know. Let me know if I should do anything else here. |
@mankins did you try adding those polyfills configuration in our docs? My hesitation with making this switch is it does not eliminate |
Some context: I was doing this for I'm not sure which polyfills in your docs you were referring to (the stream one above? how does that relate to
I'm seeing I could also expand the PR and change out the rest if that would get this merged. |
Good point. I didn't not realize that. In that case can you update ripple-keypairs's version to be |
Ok, updated. |
@@ -161,7 +161,7 @@ const ED25519_SEED = [0x01, 0xe1, 0x4b] | |||
|
|||
const codecOptions = { | |||
sha256(bytes: Uint8Array): Buffer { | |||
return createHash('sha256').update(Buffer.from(bytes)).digest() | |||
return Buffer.from(hashjs.sha256().update(bytes).digest()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when I originally made this library, the hash function was configurable iirc
"bring your own hash" :)
hashjs will be a bit of a perf drop for some use cases ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be nice, but is it still configurable? I didn't see that option.
For the record I'd prefer a library that looks for native crypto support and uses that, falling back to a trusted implementation that will work in all environments. create-hash
almost does this, but it requires manually choosing one implementation or another rather than falling back. I also prefer the more standard signature createHash('sha256').update(...
... of course I just want the package to work because I'd rather use it than not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strange, createHash should use crypto when running on node, then use the "browser" versions in the browser.
Maybe you are using it in a strange environment and are missing some polyfills that some build tools like webpack usually automatically bundle.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's because it's compiled for Tauri ... you're right though I should try to get that working again. I had seen this as a quick route without downsides, but maybe that's not the case in practice.
Was ///years/// ago
2015
|
I'm going to close this, as it's stale and I got the library working with more polyfilling as suggested above. Would be cool to make |
High Level Overview of Change
Swap create-hash sha-256 implementation for hash.js which works in more environments.
Context of Change
I was getting an error similar to browserify/createHash#30 and found that swapping out the implementation fixed the referenced error. I see hash.js is used in other parts of the xrpl ecosystem too.
Type of Change
Before / After
There should be no change to existing running code. This allows the code to be run in more ecosytems (such as Tauri + Sveltekit where I'm running this).
Test Plan
Existing tests pass.