Skip to content

Commit

Permalink
remove old js package and use js_interop instead
Browse files Browse the repository at this point in the history
  • Loading branch information
konsultaner committed Feb 27, 2024
1 parent ab53265 commit 3d25587
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
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].toJS);
}
}
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.toJS);
return list;
}
}
Expand Down

0 comments on commit 3d25587

Please sign in to comment.