Skip to content

Commit 740ab0a

Browse files
committed
Add WASM support.
1 parent 4ba46dc commit 740ab0a

File tree

84 files changed

+1036
-921
lines changed

Some content is hidden

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

84 files changed

+1036
-921
lines changed

.github/workflows/dart.yml

Lines changed: 160 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,172 @@
11
name: Dart CI
22

3-
on: [push, pull_request]
3+
env:
4+
PANA_SCORE_THRESHOLD: 20
5+
LOWEST_SUPPORTED_FLUTTER_SDK: 3.38.1
6+
FLUTTER_SDK: 3.38.1
7+
8+
on:
9+
push:
10+
branches:
11+
- master
12+
pull_request:
413

514
jobs:
6-
test:
7-
runs-on: ${{ matrix.os }}
15+
dart_format:
16+
name: "Dart: formatting"
17+
runs-on: ubuntu-slim
818
strategy:
19+
fail-fast: false
920
matrix:
10-
os: [ubuntu-latest]
11-
sdk: [stable, beta, dev]
21+
package:
22+
- cryptography
23+
- cryptography_test
24+
- jwk
1225
steps:
26+
- uses: dart-lang/setup-dart@v1
1327
- uses: actions/checkout@v3
28+
- name: Verify that code is formatted
29+
run: dart format --set-exit-if-changed .
30+
working-directory: "./${{ matrix.package }}"
31+
dart_test:
32+
name: "Dart: test"
33+
needs: format
34+
runs-on: ubuntu-latest
35+
strategy:
36+
fail-fast: false
37+
matrix:
38+
package:
39+
- cryptography
40+
- jwk
41+
compiler:
42+
- vm
43+
- dart2js
44+
- dart2wasm
45+
sdk:
46+
# The oldest supported Dart SDK at the moment.
47+
# Feel free to bump it up whenever needed.
48+
- 3.6.0
49+
- beta
50+
steps:
51+
- uses: browser-actions/setup-chrome@v2
52+
if: ${{ matrix.compiler != 'vm' }}
1453
- uses: dart-lang/setup-dart@v1
1554
with:
1655
sdk: ${{ matrix.sdk }}
17-
- name: Run tests (cryptography)
18-
run: dart test --platform vm
19-
working-directory: ./cryptography
20-
- name: Run tests (cryptography_test)
21-
run: dart test --platform vm
22-
working-directory: ./cryptography_test
23-
- name: Run tests (jwk)
24-
run: dart test --platform vm
25-
working-directory: ./jwk
26-
- name: Analyze (cryptography)
27-
run: dart analyze
28-
working-directory: ./cryptography
29-
- name: Analyze (jwk)
56+
- uses: actions/checkout@v3
57+
- name: Get dependencies
58+
run: dart pub get
59+
working-directory: ./${{ matrix.package }}
60+
- name: Analyze
3061
run: dart analyze
31-
working-directory: ./jwk
62+
working-directory: ./${{ matrix.package }}
63+
- name: "Test: VM build"
64+
if: ${{ matrix.compiler == 'vm' }}
65+
run: dart test --platform vm
66+
working-directory: ./${{ matrix.package }}
67+
- name: "Test: JS build"
68+
if: ${{ matrix.compiler == 'dart2js' }}
69+
run: dart test --platform chrome --compiler dart2js
70+
working-directory: ./${{ matrix.package }}
71+
- name: "Test: WASM build"
72+
if: ${{ matrix.compiler == 'dart2wasm' }}
73+
run: dart test --platform chrome --compiler dart2wasm
74+
working-directory: ./${{ matrix.package }}
75+
dart_package_health:
76+
name: "Dart: analyze package health"
77+
needs: analyze
78+
runs-on: ubuntu-slim
79+
strategy:
80+
fail-fast: false
81+
matrix:
82+
package:
83+
- cryptography
84+
- jwk
85+
steps:
86+
- uses: dart-lang/setup-dart@v1
87+
- uses: actions/checkout@v3
88+
- name: Get dependencies
89+
run: dart pub get
90+
working-directory: ./${{ matrix.package }}
91+
- name: Print outdated dependencies
92+
run: dart pub outdated
93+
working-directory: ./${{ matrix.package }}
94+
- name: Install package analyzer
95+
run: dart pub global activate pana
96+
- name: Run package analyzer
97+
run: dart pub global run pana --exit-code-threshold $PANA_SCORE_THRESHOLD
98+
working-directory: ./${{ matrix.package }}
99+
#
100+
# Flutter packages: analyze
101+
#
102+
flutter_analyze:
103+
name: "Flutter: analyze"
104+
runs-on: ubuntu-latest
105+
strategy:
106+
fail-fast: false
107+
matrix:
108+
package:
109+
- cryptography_flutter
110+
- cryptography_flutter_integration_test
111+
sdk:
112+
# The oldest supported Dart SDK at the moment.
113+
# Feel free to bump it up whenever needed.
114+
- 3.38.0
115+
- beta
116+
steps:
117+
- name: Install Flutter
118+
run: |
119+
cd $HOME
120+
git clone https://github.com/flutter/flutter.git --depth 1 -b $FLUTTER_SDK _flutter
121+
echo "$HOME/_flutter/bin" >> $GITHUB_PATH
122+
cd $GITHUB_WORKSPACE
123+
- uses: actions/checkout@v3
124+
- name: Get dependencies
125+
run: flutter pub get
126+
working-directory: ./${{ matrix.package }}
127+
- name: Verify that code is formatted
128+
run: dart format --set-exit-if-changed .
129+
working-directory: ./${{ matrix.package }}
130+
- name: Analyze
131+
run: flutter analyze
132+
working-directory: ./${{ matrix.package }}
133+
134+
#
135+
# Unfortunately we don't have Flutter integration tests running in Gitlab.
136+
#
137+
# If someone wants to add them, that would be great.
138+
#
139+
140+
#
141+
# Flutter packages: analyze
142+
#
143+
flutter_package_health:
144+
name: "Flutter: check package health"
145+
needs: analyze
146+
strategy:
147+
fail-fast: false
148+
matrix:
149+
package:
150+
- cryptography
151+
- jwk
152+
runs-on: ubuntu-latest
153+
steps:
154+
- name: Install Flutter
155+
run: |
156+
cd $HOME
157+
git clone https://github.com/flutter/flutter.git --depth 1 -b $FLUTTER_SDK _flutter
158+
echo "$HOME/_flutter/bin" >> $GITHUB_PATH
159+
cd $GITHUB_WORKSPACE
160+
- uses: actions/checkout@v3
161+
- name: Get dependencies
162+
run: flutter pub get
163+
working-directory: ./${{ matrix.package }}
164+
- name: Print outdated dependencies
165+
run: flutter pub outdated
166+
working-directory: ./${{ matrix.package }}
167+
- name: Install package analyzer
168+
run: flutter pub global activate pana
169+
working-directory: ./${{ matrix.package }}
170+
- name: Run package analyzer
171+
run: flutter pub global run pana --exit-code-threshold $PANA_SCORE_THRESHOLD
172+
working-directory: ./${{ matrix.package }}

.github/workflows/publish.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: Publish to pub.dev
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v[0-9]+.[0-9]+.[0-9]+'
7+
8+
jobs:
9+
publish:
10+
permissions:
11+
id-token: write
12+
uses: dart-lang/setup-dart/.github/workflows/publish.yml@daef289245bc5d4ab7864e0788a58108a9be6c99
13+
with:
14+
environment: pub.dev

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
Cryptographic packages for [Dart](https://dart.dev) / [Flutter](https://flutter.dev) developers.
77
Open-sourced under the [Apache License 2.0](LICENSE).
88

9-
Maintained by [gohilla.com](https://gohilla.com). Licensed under the [Apache License 2.0](LICENSE).
9+
Maintained by [terrier989](https://github.com/terrier989). Licensed under the [Apache License 2.0](LICENSE).
1010

1111
## Packages
1212
* [cryptography](cryptography)
@@ -28,4 +28,6 @@ Maintained by [gohilla.com](https://gohilla.com). Licensed under the [Apache Lic
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 by adopting '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: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
platforms: [ vm, chrome ]
1+
platforms:
2+
- vm
3+
- chrome
4+
compilers:
5+
- dart2wasm
6+
- dart2js

cryptography/lib/browser.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
'This library will be removed in a future major version.'
1818
' You can find `BrowserCryptography` class in "package:cryptography/cryptography.dart".',
1919
)
20-
library cryptography.browser;
20+
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424
///
2525
/// ## Factory methods
2626
/// [Cryptography] contains factory methods for cryptographic algorithms.
27-
library cryptography;
27+
library;
2828

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';

cryptography/lib/dart.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
/// Cryptographic algorithms implemented in pure Dart.
1616
///
1717
/// See [DartCryptography].
18-
library cryptography.dart;
18+
library;
1919

2020
import 'package:cryptography/dart.dart';
2121

cryptography/lib/helpers.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// limitations under the License.
1414

1515
/// Various helpers for cryptography.
16-
library cryptography.helpers;
16+
library;
1717

1818
export 'src/helpers/constant_time_equality.dart';
1919
export 'src/helpers/delegating_classes.dart';

0 commit comments

Comments
 (0)