From 3d255877561e30b5054057021047c74b458cc003 Mon Sep 17 00:00:00 2001 From: Richard Burkhardt Date: Tue, 27 Feb 2024 12:29:59 +0100 Subject: [PATCH] remove old js package and use js_interop instead --- lib/src/platform_check/node_crypto.dart | 13 +++++++++---- lib/src/platform_check/web.dart | 5 ++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/src/platform_check/node_crypto.dart b/lib/src/platform_check/node_crypto.dart index 36f6a377..b4e9bd57 100644 --- a/lib/src/platform_check/node_crypto.dart +++ b/lib/src/platform_check/node_crypto.dart @@ -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); + } } diff --git a/lib/src/platform_check/web.dart b/lib/src/platform_check/web.dart index 3ce9e6c4..4e49c2af 100644 --- a/lib/src/platform_check/web.dart +++ b/lib/src/platform_check/web.dart @@ -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'; @@ -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; } }