dchest / tweetnacl-js

Port of TweetNaCl cryptographic library to JavaScript
https://tweetnacl.js.org
The Unlicense
1.78k stars 294 forks source link

refactor: convert to native esm #261

Open PhearZero opened 8 months ago

PhearZero commented 8 months ago

Overview

Node 16 and all major browsers now support esm modules. This proposes refactoring the module in a non-breaking way in order to better leverage modern bundlers.

This could be refactored to be less code changes, this work was just looking for bundle optimizations for an sdk module. The least amount of changes would be having a single file. I have no issues with reworking this PR just seeing how difficult it would be and learning more about it's structure.

TODO

Legal Assertion

I dedicate any and all copyright interest in this software to the public domain. I make this dedication for the benefit of the public at large and to the detriment of my heirs and successors. I intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law.

Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.

PhearZero commented 8 months ago

@dchest I have a way to load the random number generator in an esm friendly way for node.js.

If the browser doesn't support an RNG, this should fail with the check for process

Relates to: https://github.com/StableLib/stablelib/pull/51#issuecomment-1139517047