Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add dart2wasm support #226

Merged
merged 2 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions lib/src/platform_check/node_crypto.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
/// Wrapper for needed NodeJS Crypto library function and require.
@JS()
library nodecryto;

import 'package:js/js.dart';
import 'dart:js_interop';
import 'dart:js_interop_unsafe';

external dynamic require(String id);
@JS()
external JSObject require(String id);

@JS()
@staticInterop
class NodeCrypto {
external randomFillSync(buf);
static JSAny randomFillSync(JSAny buf) {
final crypto = require('crypto');
return crypto.callMethod('randomFillSync'.toJS, buf);
}
}
5 changes: 2 additions & 3 deletions lib/src/platform_check/web.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
@JS()
import 'dart:js_interop';
import 'dart:math';
import 'dart:typed_data';

import 'package:js/js.dart';
import 'package:pointycastle/src/impl/entropy.dart';

import 'node_crypto.dart';
Expand Down Expand Up @@ -56,9 +56,8 @@ class _JsBuiltInEntropySource implements EntropySource {
class _JsNodeEntropySource implements EntropySource {
@override
Uint8List getBytes(int len) {
final j = require('crypto') as NodeCrypto;
var list = Uint8List(len);
j.randomFillSync(list);
NodeCrypto.randomFillSync(list.buffer.toJS);
return list;
}
}
Expand Down
Loading