Skip to content

Commit 0e0d8a0

Browse files
Remember, WASM is good.
1 parent 6437a1d commit 0e0d8a0

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# v0.1.2
22

3-
- Add support for Node.js.
3+
- Add support for Node.js and WASM.
44

55
# v0.1.1
66

dart_test.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
platforms: [ vm, chrome, node ]
1+
platforms: [ vm, chrome, firefox, node ]
2+
compilers: [ kernel, dart2js, dart2wasm ]

lib/src/core/random_fill_sync_js.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
import 'dart:js_interop';
22
import 'dart:typed_data';
33

4+
import 'package:ipcrypt/src/core/random_fill_sync_vm.dart' as vm;
5+
46
@JS()
57
external NodeCrypto require(final String id);
68

79
extension type NodeCrypto._(JSObject _) implements JSObject {
810
external JSObject randomFillSync(final JSArrayBuffer buffer);
911
}
1012

11-
@JS('crypto.getRandomValues')
12-
external JSObject getRandomValues(final JSUint8Array bytes);
13-
1413
/// Fills [bytes] with cryptographically secure random values.
1514
void randomFillSync(final Uint8List bytes) {
1615
try {
1716
// Web browser (more commonly used Dart platform than Node.js)
18-
getRandomValues(bytes.toJS);
17+
vm.randomFillSync(bytes);
1918
} catch (_) {
2019
// Node.js
2120
require('crypto').randomFillSync(bytes.buffer.toJS);

lib/src/core/utils.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import 'dart:typed_data';
22

33
import 'package:ipcrypt/src/core/random_fill_sync_stub.dart'
44
if (dart.library.io) 'package:ipcrypt/src/core/random_fill_sync_vm.dart'
5-
if (dart.library.js) 'package:ipcrypt/src/core/random_fill_sync_js.dart'
5+
if (dart.library.js_interop) 'package:ipcrypt/src/core/random_fill_sync_js.dart'
66
as rf;
77

88
/// Convert an IP address string to its 16-byte representation.

0 commit comments

Comments
 (0)