Skip to content
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 for older node versions #5

Merged
merged 1 commit into from
May 29, 2023
Merged

Support for older node versions #5

merged 1 commit into from
May 29, 2023

Conversation

benjreinhart
Copy link
Contributor

There is one piece of this library that doesn't play nice with older versions of node (< 19). That piece is the call to get random bytes, which is currently implemented using WebCrypto's crypto.getRandomValues. crypto is not available in the global scope in older node versions and thus will break.

This PR:

  1. Creates two files (csprng.ts and csprng.node.ts) that each export the same function getRandomBytes but with different implementations (one for the browser, one for node)
  2. Instructs the node runtime and bundlers which file(s) to use in which context. Node should know that when we require the csprng package subpath, we mean for it to use the node one. Similarly, bundlers should know to use the browser one when bundling for the browser.

@benjreinhart benjreinhart requested a review from asta-li May 28, 2023 23:12
@@ -1,3 +1,5 @@
import {getRandomBytes} from 'shamir-secret-sharing/csprng';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the contents of package.json, this import should be handled differently in different environments. Node should know to use the csprng.node.js file while bundling for the browser should use csprng.js

Copy link
Contributor

@asta-li asta-li left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@benjreinhart benjreinhart merged commit 9183a96 into main May 29, 2023
1 check passed
@benjreinhart benjreinhart deleted the node-support branch May 29, 2023 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants