Skip to content

Commit f8c3561

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

File tree

85 files changed

+1024
-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.

85 files changed

+1024
-921
lines changed

.github/workflows/dart.yml

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

3-
on: [push, pull_request]
3+
env:
4+
PANA_SCORE_THRESHOLD: 20
5+
6+
on:
7+
push:
8+
branches:
9+
- master
10+
pull_request:
411

512
jobs:
6-
test:
7-
runs-on: ${{ matrix.os }}
13+
format:
14+
name: Formatting
15+
runs-on: ubuntu-slim
816
strategy:
17+
fail-fast: false
918
matrix:
10-
os: [ubuntu-latest]
11-
sdk: [stable, beta, dev]
19+
package:
20+
- cryptography
21+
- cryptography_test
22+
- jwk
1223
steps:
24+
- uses: dart-lang/setup-dart@v1
1325
- uses: actions/checkout@v3
26+
- name: Verify that code is formatted
27+
run: dart format --set-exit-if-changed .
28+
working-directory: "./${{ matrix.package }}"
29+
test:
30+
name: Test
31+
needs: format
32+
runs-on: ubuntu-latest
33+
strategy:
34+
fail-fast: false
35+
matrix:
36+
package:
37+
- cryptography
38+
- jwk
39+
compiler:
40+
- vm
41+
- dart2js
42+
- dart2wasm
43+
sdk:
44+
# The oldest supported Dart SDK at the moment.
45+
# Feel free to bump it up whenever needed.
46+
- 3.6.0
47+
- beta
48+
steps:
49+
- uses: browser-actions/setup-chrome@v2
50+
if: matrix.compiler != vm
1451
- uses: dart-lang/setup-dart@v1
1552
with:
1653
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)
54+
- uses: actions/checkout@v3
55+
- name: Get dependencies
56+
run: dart --version && dart pub get
57+
working-directory: ./${{ matrix.package }}
58+
- name: Analyze
3059
run: dart analyze
31-
working-directory: ./jwk
60+
working-directory: ./${{ matrix.package }}
61+
- name: "Test: VM build"
62+
if: matrix.compiler == 'vm'
63+
run: dart test --platform vm
64+
working-directory: ./${{ matrix.package }}
65+
- name: "Test: JS build"
66+
if: matrix.compiler == 'dart2js'
67+
run: dart test --platform chrome --compiler dart2js
68+
working-directory: ./${{ matrix.package }}
69+
- name: "Test: WASM build"
70+
if: matrix.compiler == 'dart2wasm'
71+
run: dart test --platform chrome --compiler dart2wasm
72+
working-directory: ./${{ matrix.package }}
73+
package_health:
74+
name: Analyze package health
75+
needs: analyze
76+
runs-on: ubuntu-slim
77+
strategy:
78+
fail-fast: false
79+
matrix:
80+
package:
81+
- cryptography
82+
- jwk
83+
steps:
84+
- uses: actions/checkout@v3
85+
- uses: dart-lang/setup-dart@v1
86+
- name: Install dependencies
87+
run: dart --version && dart pub get && dart pub global activate pana
88+
- name: Run package analyzer
89+
run: dart pub global run pana --exit-code-threshold $PANA_SCORE_THRESHOLD
90+
working-directory: ./${{ matrix.package }}

.github/workflows/flutter.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: Flutter CI
2+
3+
env:
4+
LOWEST_SUPPORTED_FLUTTER_SDK: 3.38.1
5+
PANA_SCORE_THRESHOLD: 20
6+
7+
on:
8+
push:
9+
branches:
10+
- master
11+
pull_request:
12+
13+
jobs:
14+
analyze:
15+
name: "Analyze"
16+
runs-on: ubuntu-latest
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
package:
21+
- cryptography_flutter
22+
- cryptography_flutter_integration_test
23+
sdk:
24+
# The oldest supported Dart SDK at the moment.
25+
# Feel free to bump it up whenever needed.
26+
- 3.38.0
27+
- beta
28+
steps:
29+
- name: Install Flutter
30+
run: |
31+
cd $HOME
32+
git clone https://github.com/flutter/flutter.git --depth 1 -b dev _flutter
33+
echo "$HOME/_flutter/bin" >> $GITHUB_PATH
34+
cd $GITHUB_WORKSPACE
35+
- uses: actions/checkout@v3
36+
- name: Get dependencies
37+
run: flutter pub get
38+
working-directory: ./${{ matrix.package }}
39+
- name: Verify that code is formatted
40+
run: dart format --set-exit-if-changed .
41+
working-directory: ./${{ matrix.package }}
42+
- name: Analyze
43+
run: flutter analyze
44+
working-directory: ./${{ matrix.package }}
45+
package_health:
46+
name: "Check package health"
47+
needs: analyze
48+
runs-on: ubuntu-latest
49+
strategy:
50+
fail-fast: false
51+
steps:
52+
- name: Install Flutter
53+
run: |
54+
cd $HOME
55+
git clone https://github.com/flutter/flutter.git --depth 1 -b dev _flutter
56+
echo "$HOME/_flutter/bin" >> $GITHUB_PATH
57+
cd $GITHUB_WORKSPACE
58+
- name: Install package analyzer
59+
run: flutter pub global activate pana
60+
- uses: actions/checkout@v3
61+
- name: Get dependencies
62+
run: flutter pub get
63+
- name: Run package analyzer
64+
run: flutter pub global run pana --exit-code-threshold $PANA_SCORE_THRESHOLD
65+
working-directory: ./cryptography_flutter
66+
#
67+
# Unfortunately we don't have Flutter integration tests running in Gitlab.
68+
#
69+
# If someone wants to add them, that would be great.
70+
#

.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

0 commit comments

Comments
 (0)