danwallach / ElectionGuard-TypeScript

TypeScript implementation of ElectionGuard (subset for ballot encryption)
MIT License
8 stars 0 forks source link

Compatibility checker #30

Closed danwallach closed 2 years ago

danwallach commented 2 years ago

We need a function that tests whether or not the platform supports ElectionGuard-TypeScript. We need to (somehow) figure out all the different features we're using and test for each of them. The function should return some kind of structure with string keys (names of the relevant features) and boolean values (supported or unsupported).

If everything is good, then it just returns true or whatever, so it's at least easy to check that there isn't a problem.

Related: understanding what "polyfill" libraries are available and whether they're good enough. I'm pretty sure we're going to require native bigint, but other stuff? We can get away with a lot before performance becomes an issue.

shreyasminocha commented 2 years ago

I was thinking about doing all the checks in index.ts and throwing an error if something was missing. Does that also work or is the "a function that" part necessary?

Related also: We're currently building commonjs modules, which likely wouldn't work in browsers. We could set up a separate browser build, or we could try to build es6 modules, which should work in both node and browsers. The only blocker for that should be seedrandom's lack of esm module support, which I think can be fixed by replacing it with esm-seedrandom? Ugh. Nevermind, I got this part working, but I'm still unsure if the es6 modules tsc is generating will work as-is in browsers. #27

The other consideration with browsers, though, is that we probably want to output a single js file that includes everything? AFAIK tsc doesn't let us do that, so we'll have to bring in rollup or webpack or something.

danwallach commented 2 years ago

Found this: https://github.com/Modernizr/Modernizr

Unsurprisingly, there's a library that knows how to do most of the work we need.

Lets move the webpack/commonjs discussion to a separate issue. The point of this issue is just having some code in front whose job it is to fail fast if we're on an antiquated platform. Maybe this check occurs inside the GroupContext fetcher?

danwallach commented 2 years ago

Also: https://featurejs.com/

This can detect async, which is good, but neither this nor Modernizr seem to have bigint detection.

danwallach commented 2 years ago

But this has exactly what we need for bigint: https://github.com/stdlib-js/assert-has-bigint-support

danwallach commented 2 years ago

And, in fact, there are a bunch of great property detectors in the stdlib project. These are exactly what we need.

https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/assert