paulmillr / noble-ed25519

Fastest 4KB JS implementation of ed25519 signatures
https://paulmillr.com/noble
MIT License
414 stars 50 forks source link

How to create hybrid NPM package for Node.js and bundlers? #89

Closed jost-s closed 1 year ago

jost-s commented 1 year ago

I've seen the hint to shim for Node.js <= v18 to augment the global object with webcrypto features, and it works fine when executing in a Node environment. However, when my package that is importing @noble/ed25519 is bundled, the bundler stumbles over the node module import.

A workaround is a conditional async import. That makes all operation asynchronous and the bundlers are outputting warnings and polyfill suggestions.

What is your recommendation for creating a hybrid package with ed25519 that works in Node.js as well as with a bundler?

paulmillr commented 1 year ago

What is your recommendation for creating a hybrid package with ed25519 that works in Node.js as well as with a bundler

Use noble-curves. It supports hybrid modules and there is no need for a polyfill.

All other solutions that can be implemented in noble-ed25519 will make the library unloadable in browsers without bundlers.

paulmillr commented 1 year ago

The choice for every library is between:

jost-s commented 1 year ago

Thank you for your answers, I didn't receive notifications about them (something wrong with my settings). I understand, makes sense. I'll switch to noble-curves.