Skip to content

Commit 6b2411b

Browse files
authored
Merge pull request #29 from jezell/main
update to package:web
2 parents d7945ee + 6990ea8 commit 6b2411b

24 files changed

+885
-771
lines changed

lib/src/e2ee.worker/crypto.dart

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import 'dart:async';
2-
import 'dart:html' as html;
32
import 'dart:js_util' as jsutil;
43
import 'dart:typed_data';
54

65
import 'package:js/js.dart';
6+
import 'package:web/web.dart' as web;
77

88
@JS('Promise')
99
class Promise<T> {
@@ -18,14 +18,14 @@ class Algorithm {
1818
@JS('crypto.subtle.encrypt')
1919
external Promise<ByteBuffer> encrypt(
2020
dynamic algorithm,
21-
html.CryptoKey key,
21+
web.CryptoKey key,
2222
ByteBuffer data,
2323
);
2424

2525
@JS('crypto.subtle.decrypt')
2626
external Promise<ByteBuffer> decrypt(
2727
dynamic algorithm,
28-
html.CryptoKey key,
28+
web.CryptoKey key,
2929
ByteBuffer data,
3030
);
3131

@@ -52,7 +52,7 @@ ByteBuffer jsArrayBufferFrom(List<int> data) {
5252
}
5353

5454
@JS('crypto.subtle.importKey')
55-
external Promise<html.CryptoKey> importKey(
55+
external Promise<web.CryptoKey> importKey(
5656
String format,
5757
ByteBuffer keyData,
5858
dynamic algorithm,
@@ -63,28 +63,28 @@ external Promise<html.CryptoKey> importKey(
6363
@JS('crypto.subtle.exportKey')
6464
external Promise<ByteBuffer> exportKey(
6565
String format,
66-
html.CryptoKey key,
66+
web.CryptoKey key,
6767
);
6868

6969
@JS('crypto.subtle.deriveKey')
70-
external Promise<html.CryptoKey> deriveKey(
70+
external Promise<web.CryptoKey> deriveKey(
7171
dynamic algorithm,
72-
html.CryptoKey baseKey,
72+
web.CryptoKey baseKey,
7373
dynamic derivedKeyAlgorithm,
7474
bool extractable,
7575
List<String> keyUsages);
7676

7777
@JS('crypto.subtle.deriveBits')
7878
external Promise<ByteBuffer> deriveBits(
7979
dynamic algorithm,
80-
html.CryptoKey baseKey,
80+
web.CryptoKey baseKey,
8181
int length,
8282
);
8383

84-
Future<html.CryptoKey> impportKeyFromRawData(List<int> secretKeyData,
84+
Future<web.CryptoKey> impportKeyFromRawData(List<int> secretKeyData,
8585
{required String webCryptoAlgorithm,
8686
required List<String> keyUsages}) async {
87-
return jsutil.promiseToFuture<html.CryptoKey>(importKey(
87+
return jsutil.promiseToFuture<web.CryptoKey>(importKey(
8888
'raw',
8989
jsArrayBufferFrom(secretKeyData),
9090
jsutil.jsify({'name': webCryptoAlgorithm}),

lib/src/e2ee.worker/e2ee.cryptor.dart

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import 'dart:async';
2-
import 'dart:html';
32
import 'dart:js';
3+
import 'dart:js_interop';
44
import 'dart:js_util' as jsutil;
55
import 'dart:math';
66
import 'dart:typed_data';
77

88
import 'package:dart_webrtc/src/rtc_transform_stream.dart';
9+
import 'package:web/web.dart' as web;
10+
911
import 'crypto.dart' as crypto;
1012
import 'e2ee.keyhandler.dart';
1113
import 'e2ee.logger.dart';
@@ -136,7 +138,7 @@ class FrameCryptor {
136138
bool _enabled = false;
137139
CryptorError lastError = CryptorError.kNew;
138140
int currentKeyIndex = 0;
139-
final DedicatedWorkerGlobalScope worker;
141+
final web.DedicatedWorkerGlobalScope worker;
140142
SifGuard sifGuard = SifGuard();
141143

142144
void setParticipant(String identity, ParticipantKeyHandler keys) {
@@ -219,7 +221,7 @@ class FrameCryptor {
219221
}
220222

221223
void postMessage(Object message) {
222-
worker.postMessage(message);
224+
worker.postMessage(message.jsify());
223225
}
224226

225227
Future<void> setupTransform({
@@ -480,7 +482,7 @@ class FrameCryptor {
480482
));
481483

482484
if (currentkeySet != initialKeySet) {
483-
logger.warning(
485+
logger.fine(
484486
'ratchetKey: decryption ok, reset state to kKeyRatcheted');
485487
await keyHandler.setKeySetFromMaterial(
486488
currentkeySet, initialKeyIndex);

lib/src/e2ee.worker/e2ee.keyhandler.dart

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import 'dart:async';
2-
import 'dart:html';
32
import 'dart:js_util' as jsutil;
43
import 'dart:typed_data';
54

5+
import 'package:web/web.dart' as web;
6+
67
import 'crypto.dart' as crypto;
78
import 'e2ee.logger.dart';
89
import 'e2ee.utils.dart';
@@ -29,7 +30,7 @@ class KeyOptions {
2930

3031
class KeyProvider {
3132
KeyProvider(this.worker, this.id, this.keyProviderOptions);
32-
final DedicatedWorkerGlobalScope worker;
33+
final web.DedicatedWorkerGlobalScope worker;
3334
final String id;
3435
final KeyOptions keyProviderOptions;
3536
var participantKeys = <String, ParticipantKeyHandler>{};
@@ -80,8 +81,8 @@ const KEYRING_SIZE = 16;
8081

8182
class KeySet {
8283
KeySet(this.material, this.encryptionKey);
83-
CryptoKey material;
84-
CryptoKey encryptionKey;
84+
web.CryptoKey material;
85+
web.CryptoKey encryptionKey;
8586
}
8687

8788
class ParticipantKeyHandler {
@@ -100,7 +101,7 @@ class ParticipantKeyHandler {
100101

101102
final KeyOptions keyOptions;
102103

103-
final DedicatedWorkerGlobalScope worker;
104+
final web.DedicatedWorkerGlobalScope worker;
104105

105106
final String participantIdentity;
106107

@@ -157,8 +158,8 @@ class ParticipantKeyHandler {
157158
return newKey;
158159
}
159160

160-
Future<CryptoKey> ratchetMaterial(
161-
CryptoKey currentMaterial, ByteBuffer newKeyBuffer) async {
161+
Future<web.CryptoKey> ratchetMaterial(
162+
web.CryptoKey currentMaterial, ByteBuffer newKeyBuffer) async {
162163
var newMaterial = await jsutil.promiseToFuture(crypto.importKey(
163164
'raw',
164165
newKeyBuffer,
@@ -194,14 +195,14 @@ class ParticipantKeyHandler {
194195

195196
/// Derives a set of keys from the master key.
196197
/// See https://tools.ietf.org/html/draft-omara-sframe-00#section-4.3.1
197-
Future<KeySet> deriveKeys(CryptoKey material, Uint8List salt) async {
198+
Future<KeySet> deriveKeys(web.CryptoKey material, Uint8List salt) async {
198199
var algorithmOptions =
199200
getAlgoOptions((material.algorithm as crypto.Algorithm).name, salt);
200201

201202
// https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/deriveKey#HKDF
202203
// https://developer.mozilla.org/en-US/docs/Web/API/HkdfParams
203204
var encryptionKey =
204-
await jsutil.promiseToFuture<CryptoKey>(crypto.deriveKey(
205+
await jsutil.promiseToFuture<web.CryptoKey>(crypto.deriveKey(
205206
jsutil.jsify(algorithmOptions),
206207
material,
207208
jsutil.jsify({'name': 'AES-GCM', 'length': 128}),
@@ -215,7 +216,7 @@ class ParticipantKeyHandler {
215216
/// Ratchets a key. See
216217
/// https://tools.ietf.org/html/draft-omara-sframe-00#section-4.3.5.1
217218
218-
Future<Uint8List> ratchet(CryptoKey material, Uint8List salt) async {
219+
Future<Uint8List> ratchet(web.CryptoKey material, Uint8List salt) async {
219220
var algorithmOptions = getAlgoOptions('PBKDF2', salt);
220221

221222
// https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/deriveBits

lib/src/e2ee.worker/e2ee.utils.dart

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import 'dart:html';
21
import 'dart:js' as js;
32
import 'dart:typed_data';
43

4+
import 'package:js/js_util.dart';
5+
import 'package:web/web.dart' as web;
6+
57
import 'crypto.dart' as crypto;
68

79
bool isE2EESupported() {
@@ -17,10 +19,10 @@ bool isInsertableStreamSupported() {
1719
js.context['RTCRtpSender']['prototype']['createEncodedStreams'] != null;
1820
}
1921

20-
Future<CryptoKey> importKey(
22+
Future<web.CryptoKey> importKey(
2123
Uint8List keyBytes, String algorithm, String usage) {
2224
// https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/importKey
23-
return promiseToFuture<CryptoKey>(crypto.importKey(
25+
return promiseToFuture<web.CryptoKey>(crypto.importKey(
2426
'raw',
2527
crypto.jsArrayBufferFrom(keyBytes),
2628
js.JsObject.jsify({'name': algorithm}),
@@ -29,10 +31,10 @@ Future<CryptoKey> importKey(
2931
));
3032
}
3133

32-
Future<CryptoKey> createKeyMaterialFromString(
34+
Future<web.CryptoKey> createKeyMaterialFromString(
3335
Uint8List keyBytes, String algorithm, String usage) {
3436
// https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/importKey
35-
return promiseToFuture<CryptoKey>(crypto.importKey(
37+
return promiseToFuture<web.CryptoKey>(crypto.importKey(
3638
'raw',
3739
crypto.jsArrayBufferFrom(keyBytes),
3840
js.JsObject.jsify({'name': 'PBKDF2'}),

0 commit comments

Comments
 (0)