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

Make this workable ES-compliant platforms (like browsers) by generalising crypto and performance APIs #2

Open
CMCDragonkai opened this issue Oct 11, 2021 · 1 comment
Labels
enhancement New feature or request r&d:polykey:core activity 2 Cross Platform Cryptography for JavaScript Platforms

Comments

@CMCDragonkai
Copy link
Member

Is your feature request related to a problem? Please describe.

Right now js-id only works in node due to 2 imports:

import crypto from 'crypto';
import { performance } from 'perf_hooks';

Both of these are part of ES standards:

Therefore it should be possible to use the JS APIs without importing node specific libraries.

Describe the solution you'd like

Attempt to use top-level await to create modules that work in nodejs and general JS platforms.

This was attempted already in:

This will require updating the ecosystem dependencies. It's quite experimental features.

Describe alternatives you've considered

One can also bundle a browser version of the script. However I've come to dislike this method because it introduces lots of dependencies and makes it more difficult to bundle at the end. IMO bundling should only occur at the application point, not at the library. The library itself should be made generic. This reduces maintenance overhead.

Additional context

See #1 for the development of this library.

@CMCDragonkai
Copy link
Member Author

We now have toBuffer and fromBuffer to ensure that ids are properly converted without copying.

In dynamic JS, this shouldn't be a problem since it's only called when the function is called.

In TS with in non-node environments, there may be type errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request r&d:polykey:core activity 2 Cross Platform Cryptography for JavaScript Platforms
Development

No branches or pull requests

2 participants