Skip to content

Commit ba54b4a

Browse files
authored
Merge pull request #201 from dint-dev/feature/wasm
Implement dart2wasm support
2 parents 4b7f0a8 + 5fc819d commit ba54b4a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+775
-799
lines changed

.github/workflows/dart.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ jobs:
6464
compiler:
6565
- vm
6666
- dart2js
67+
- dart2wasm
6768
steps:
6869
- uses: browser-actions/setup-chrome@v2
6970
if: ${{ matrix.compiler != 'vm' }}
@@ -79,9 +80,13 @@ jobs:
7980
run: dart test --platform vm
8081
working-directory: ./${{ matrix.package }}
8182
- name: "Test: JS build"
82-
if: ${{ matrix.compiler == 'vm' }}
83+
if: ${{ matrix.compiler == 'dart2js' }}
8384
run: dart test --platform chrome --compiler dart2js
8485
working-directory: ./${{ matrix.package }}
86+
- name: "Test: WASM build"
87+
if: ${{ matrix.compiler == 'dart2wasm' }}
88+
run: dart test --platform chrome --compiler dart2wasm
89+
working-directory: ./${{ matrix.package }}
8590

8691
#
8792
# Dart packages: PANA score

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,6 @@ Maintained by [terrier989](https://github.com/terrier989). Licensed under the [A
2828
Please share feedback / issue reports in the
2929
[issue tracker](https://github.com/dint-dev/cryptography/issues).
3030

31-
Pull requests are welcome.
31+
Pull requests are welcome.
32+
33+
## Testing

cryptography/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 2.8.0
2+
* Adds WASM support. `BrowserCryptography` now uses 'dart:js_interop'.
3+
14
## 2.7.0
25
* Adds a cross-platform of Argon2id, a highly recommended algorithm for password hashing.
36
* Introduces a dependency on "package:ffi" (a package by Google). A memory allocator in the package

cryptography/README.md

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,27 @@
66
Popular cryptographic algorithms for [Dart](https://dart.dev) / [Flutter](https://flutter.dev)
77
developers.
88

9-
Maintained by [gohilla.com](https://gohilla.com). Licensed under the [Apache License 2.0](LICENSE).
10-
11-
This package is designed to be:
12-
13-
* __Easy to use__. The API is easy to understand and encourages good defaults.
14-
* __Multi-platform__. It's easy to customize implementation of X in platform Y.
15-
* __Fast.__ We use platform APIs when available. For example, SHA-512 is over 100 times faster than
16-
_package:crypto_ in browsers.
9+
Maintained by [terrier989](https://github.com/terrier989).
10+
Licensed under the [Apache License 2.0](LICENSE).
11+
12+
## Key features
13+
* __Defaults to platform-provided implementations.__
14+
* Android: [javax.crypto](https://developer.android.com/reference/javax/crypto/package-summary)
15+
* iOS / Mac OS X: [Apple CryptoKit](https://developer.apple.com/documentation/cryptokit/)
16+
* Web: [Web Crypto API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API)
17+
* __Works in all platforms.__
18+
* We have written Dart implementations for the vast majority of algorithms. When a platform does
19+
not provide a required algorithm, the package automatically falls back to pure Dart
20+
implementation.
21+
* In browsers, both Javascript and WASM compilers are supported. Dart implementations of 64-bit
22+
algorithms like Blake2B have been written to work with Javascript's 53-bit integers.
23+
* __Flexible.__
24+
* You can override factory methods in [Cryptography](https://pub.dev/documentation/cryptography/latest/cryptography/Cryptography-class.html)
25+
class if you want to use something else. Note that algorithms that you don't use do not affect
26+
size of the executable because of tree pruning.
27+
* You can override random number generator with a deterministic one for tests.
28+
* __Fast.__
29+
* For example, SHA-512 is over 100 times faster than _package:crypto_ in browsers.
1730

1831
Any feedback, issue reports, or pull requests are appreciated!
1932

@@ -33,8 +46,10 @@ Android / iOS / Mac OS X operating system APIs whenever possible.
3346
In _pubspec.yaml_:
3447
```yaml
3548
dependencies:
36-
cryptography: ^2.7.0
37-
cryptography_flutter: ^2.3.2 # Remove if you don't use Flutter
49+
cryptography: ^2.8.0
50+
51+
# If you are writing a Flutter app/package, also add this:
52+
cryptography_flutter: ^2.3.3
3853
```
3954
4055
You are ready to go!
@@ -239,8 +254,8 @@ We wrote the following three implementations of `Cryptography`:
239254
for list algorithms supported by it.
240255
* [BrowserCryptography](https://pub.dev/documentation/cryptography/latest/cryptography/BrowserCryptography-class.html)
241256
* Uses [Web Cryptography API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API)
242-
(_crypto.subtle_) whenever possible. Methods return pure Dart implementations when Web
243-
Cryptography API is not available.
257+
whenever possible. Methods return pure Dart implementations when Web Cryptography API is not
258+
available.
244259
* See the [class documentation](https://pub.dev/documentation/cryptography/latest/cryptography/BrowserCryptography-class.html)
245260
for list algorithms supported by it.
246261
* [FlutterCryptography](https://pub.dev/documentation/cryptography_flutter/latest/cryptography_flutter/FlutterCryptography-class.html)

cryptography/dart_test.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ platforms:
22
- vm
33
- chrome
44
compilers:
5+
- dart2wasm
56
- dart2js

cryptography/lib/browser.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@
2020
library;
2121

2222
export 'src/browser/browser_cryptography_when_not_browser.dart'
23-
if (dart.library.html) 'src/browser/browser_cryptography.dart';
23+
if (dart.library.js_interop) 'src/browser/browser_cryptography.dart';

cryptography/lib/cryptography.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ library;
2929
import 'package:cryptography/cryptography.dart';
3030

3131
export 'src/browser/browser_cryptography_when_not_browser.dart'
32-
if (dart.library.html) 'src/browser/browser_cryptography.dart';
32+
if (dart.library.js_interop) 'src/browser/browser_cryptography.dart';
3333
export 'src/cryptography/algorithms.dart';
3434
export 'src/cryptography/cipher.dart';
3535
export 'src/cryptography/cipher_state.dart';

0 commit comments

Comments
 (0)