mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-03-12 09:32:33 +00:00
Add ability to get random bytes on Linux. Used same method as in cake backups.
This commit is contained in:
parent
5c2490e721
commit
d45df36238
1 changed files with 9 additions and 2 deletions
|
@ -1,11 +1,18 @@
|
|||
import 'dart:typed_data';
|
||||
|
||||
import 'dart:io';
|
||||
import 'dart:math';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
const utils = const MethodChannel('com.cake_wallet/native_utils');
|
||||
|
||||
Future<Uint8List> secRandom(int count) async {
|
||||
try {
|
||||
if (Platform.isLinux) {
|
||||
// Used method to get securely generated random bytes from cake backups
|
||||
const byteSize = 256;
|
||||
final rng = Random.secure();
|
||||
return Uint8List.fromList(List<int>.generate(count, (_) => rng.nextInt(byteSize)));
|
||||
}
|
||||
|
||||
return await utils.invokeMethod<Uint8List>('sec_random', {'count': count}) ?? Uint8List.fromList([]);
|
||||
} on PlatformException catch (_) {
|
||||
return Uint8List.fromList([]);
|
||||
|
|
Loading…
Reference in a new issue