-
-
Notifications
You must be signed in to change notification settings - Fork 442
Migrate dart:html and package:js to package:web and dart:js_interop #698
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
Migrate dart:html and package:js to package:web and dart:js_interop #698
Conversation
Hi all, i am working on integrating #680, so this should not be needed anymore. Thank you anyway! |
#680 does still use package:js and not dart:js_interop |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the good PR! I hope this is helpful.
encryptionKey = await js_util.promiseToFuture<html.CryptoKey>( | ||
crypto.importKey("raw", jwk, algorithm, false, ["encrypt", "decrypt"]), | ||
); | ||
encryptionKey = await crypto.importKey("raw", jwk.toJS, algorithm, false, ["encrypt".toJS, "decrypt".toJS].toJS).toDart; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Creating a private extension for List<String>
seemed to increase readability. Please consider it if you like.
extension on List<String> {
JSArray<JSString> get toJS => [
...map((e) => e.toJS),
].toJS;
}
@@ -130,26 +127,24 @@ class FlutterSecureStorageWeb extends FlutterSecureStoragePlatform { | |||
required Map<String, String> options, | |||
}) async { | |||
final iv = | |||
html.window.crypto!.getRandomValues(Uint8List(12)).buffer.asUint8List(); | |||
(web.window.crypto.getRandomValues(Uint8List(12).toJS) as js_interop.JSUint8Array).toDart.buffer.asUint8List(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since getRandomValues
updates its arguments, the following implementation would reduce the toDart
and toJS
conversions.
final iv = Uint8List(12);
web.window.crypto.getRandomValues(iv.toJS);
} | ||
|
||
return map; | ||
} | ||
|
||
crypto.Algorithm _getAlgorithm(Uint8List iv) => | ||
crypto.Algorithm(name: 'AES-GCM', length: 256, iv: iv); | ||
js_interop.JSObject _getAlgorithm(Uint8List iv) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specifying JSAny
instead of JSObject
may reduce type conversion.
https://github.com/dart-lang/web/blob/v0.5.1/lib/src/dom/webcryptoapi.dart
I have updated the code with the changes provided above |
I have just tested all the changed code and noticed that the get random value does work for javascript but does not work for wasm. I will revert this change. |
Thanks! I understand that Since |
I just noticed that the jsonwebkey file isn't used anymore and could also be deleted. Should I delete this? |
@svenopdehipt - Thanks for your work on this! Is there any chance you can pull develop into this branch (or rebase) to resolve merge conflicts? 🙏 |
…op, remove dead code, update dependencies for example
… use crypto functions from package:web
I have rebased the branch with the develop branch of your repo. |
Rapid work @svenopdehipt - Thank you! My only thoughts now are relating to @koji-1009's comment above. Should our environment:
sdk: ">=3.3.0 <4.0.0"
flutter: ">=3.19.0" |
I do think that it would make sense to update the pubspec.yaml, because older flutter and dart versions aren't supported anyway due though the package:web dependency. |
Keen to hear your thoughts @juliansteenbakker, as I know you were discussing this in #680! |
Bump. Any updates on this? |
@@ -13,6 +13,7 @@ dependencies: | |||
flutter_secure_storage_platform_interface: ^1.1.1 | |||
flutter_web_plugins: | |||
sdk: flutter | |||
web: '>=0.5.0 <1.0.0' | |||
js: ^0.6.3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is js still a dependency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't know why it's shown here. When I look at the file at my repo, it isn't. https://github.com/svenopdehipt/flutter_secure_storage/blob/develop/flutter_secure_storage_web/pubspec.yaml
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just saw, that the file you reference is outdated. Please look at the changes now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh you changed it in the last commit: c9f2b62#diff-dd1ec4717f1b8774ed50d5be49319e0a3e9976c07f16f133ac101a5f07066a3e (where you added it), where you removed it: dd4d5d0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am resolving some merge conflicts due to the recent messy revert of some breaking changes, it won't be added when i merge this.
Seems all good! So what i'm gonna do is merge this, change the version constraints of flutter, and release it under a new major version. I created a separate branch where we can continue support for the current version 9, because the sudden change in flutter versions will require lots of people to update flutter, which can be a hassle in some projects. |
d484bdf
into
juliansteenbakker:develop
So, because these changes require a recent version of flutter, i have decided to make it an opt-in. dependency_overrides:
flutter_secure_storage_web: ^2.0.0-beta.1 I have also added this in the readme, so users can decide of themself to use this version, or stick with the old implementation which doesn't require the latest flutter version. |
Any updates on this? |
Migrate packages to support wasm in the next stable release.
Removed unused code in subtle.dart and update dependencies for the example project.
I have also used the new index.html structure and tested it wasm on the current beta channel, but I have reverted the index.html because it doesn't work with the current stable release.