-
Notifications
You must be signed in to change notification settings - Fork 1.7k
WebCrypto's CryptoKey type is incompatible on Dart 2.12.4 #45745
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
Comments
To add a little bit of weight to that: we're a startup in the healthcare industry doing mobile/web apps for healthcare professionals to securely collaborate about patients. Communications are encrypted end-to-end using different Dart libraries. Since the null safety migration, we're stuck on the desktop/web front because it's now impossible to do encryption/decryption in a performant matter. On mobile/native land, it's all good though. |
/cc @srujzs |
I can repro this with the latest 2.14 with dart2js (although not with ddc for some reason on either 2.14 or 2.12.4 as far as I can tell). There's definitely an issue here with the native binding since as you say the result is a The symptoms and the error very closely resemble a similar issue: #44324, but the solution of that (adding |
/cc @rakudrama Oh - I had thought dart2js conservatively assumed that any JS-interop call could return any native type, including browser native types. However, it appears that by design we decided not to: sdk/pkg/compiler/lib/src/native/behavior.dart Line 798 in b529afd
That would explain why we have a similar tree-shaking issue here. What's worse here is that it appears that there is no API in dart:html that can return a When we switch to our static js-interop approach and CryptoKey is modeled using that, then this wont be an issue anymore. Until then, I wonder what's the best approach to avoid this problem. Some possibilities:
On a separate note, once we fix the liveness issue, it may be worth noting that the example above is typing the result of the API as |
I tried this with a validation check as well where I made For example:
The following gets placed in
I think really we can do maybe one thing simpler in that if dart2js sees a |
We chatted a bit about what we can do here and trying my best to summarize:
This does present a small case study though in which it might make sense to remove this from As a workaround for now and for your purposes, Mathieu, I would suggest using an
and on usage:
Note that this will not work without Edit: On further inspection, the workaround only works because the type is not live. It might not be an issue in dart2js because CryptoKey can never be live from the way our API is written. However, on ddc, the above workaround fails because native types are always live by default. Which is frustrating because that means the only real workaround here is
|
Thanks a lot for your investigations and suggestions @srujzs and @sigmundch ! |
cc: @kevmoo This issue was opened by our team. It blocked us from using JS interop to get decent web crypto. We ended up using this which is not ideal. Turns out it's fork of a fork of an unofficial google package. (Forked because the conditional imports/SDK dependencies aren't done properly to use it in a pure web environment. Forcing us into using Flutter for web, even for a very simple page that shouldn't need flutter). |
I just ran this locally (with 2.19.0-361.0.dev (dev) (Tue Nov 1 15:30:40 2022 -0700) on "macos_arm64") and it worked fine. I'd look at https://github.com/google/webcrypto.dart if you want this functionality! |
Yes! we've looked for that, but as I mentioned, I had to fork it to remove all the flutter dependencies for one of our non-flutter web projects. Not ideal, but it works. |
See also: #50290 I ran this on latest dev and it works. Closing out... |
Given the simple test:
The test hangs and fails after 30 seconds. Running the tests with the
--pause-after-load
flag to obtain a javascript console, we can see the following exception being printed out:This happens when the code is compiled with dartdevc and dart2js (unless with
-O3
or-O4
).With
-O3
or-O4
, the test runs to completion, but fails the type assertion.Still with any of these flags, if I run the compiled code in in Chrome and set a breakpoint in the Chrome dev console, I can see that the variable is indeed a CryptoKey in Javascript land.
Environment
dart --version
): 2.12.4The text was updated successfully, but these errors were encountered: