Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:isolate';

import 'package:bip340/bip340.dart' as bip340;

import '../../../domain_layer/entities/nip_01_event.dart';
Expand All @@ -6,11 +8,18 @@ import '../../../domain_layer/repositories/event_verifier.dart';
/// Pure dart event verifier using https://pub.dev/packages/bip340
/// can be slow on mobile devices
class Bip340EventVerifier implements EventVerifier {
bool useIsolate = true;

Bip340EventVerifier({this.useIsolate = true});

@override
Future<bool> verify(Nip01Event event) async {
if (event.sig == null) {
return false;
}
return bip340.verify(event.pubKey, event.id, event.sig!);
if (!event.isIdValid) return false;
return useIsolate? await Isolate.run(() {
return bip340.verify(event.pubKey, event.id, event.sig);
}) : bip340.verify(event.pubKey, event.id, event.sig);
}
}
16 changes: 8 additions & 8 deletions packages/sample-app/lib/query_performance.dart
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ class _QueryPerformancePageState extends State<QueryPerformancePage> {
onPressed: _isVerifyingBip340 ? null : _runBip340Query,
child: _isVerifyingBip340
? const SizedBox(
height: 20,
width: 20,
child: CircularProgressIndicator(strokeWidth: 2),
)
height: 20,
width: 20,
child: CircularProgressIndicator(strokeWidth: 2),
)
: const Text('Run with BIP340'),
),
const SizedBox(height: 8),
Expand All @@ -139,10 +139,10 @@ class _QueryPerformancePageState extends State<QueryPerformancePage> {
onPressed: _isVerifyingRust ? null : _runRustQuery,
child: _isVerifyingRust
? const SizedBox(
height: 20,
width: 20,
child: CircularProgressIndicator(strokeWidth: 2),
)
height: 20,
width: 20,
child: CircularProgressIndicator(strokeWidth: 2),
)
: const Text('Run with Rust'),
),
const SizedBox(height: 8),
Expand Down
Loading