Spawn isolate for unlocking Dewif: Very slower as non isolate, so discard for now
This commit is contained in:
parent
224016d39e
commit
31bfc87d00
|
@ -2,6 +2,7 @@ import 'dart:io';
|
|||
import 'package:crypto/crypto.dart';
|
||||
import 'package:durt/durt.dart';
|
||||
import 'package:fast_base58/fast_base58.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'dart:async';
|
||||
import 'package:gecko/globals.dart';
|
||||
|
@ -25,57 +26,19 @@ class WalletOptionsProvider with ChangeNotifier {
|
|||
|
||||
Future<NewWallet> get badWallet => null;
|
||||
|
||||
String _getPubkeyFromDewif(
|
||||
String _dewif, _pin, int _pinLenght, int derivation) {
|
||||
RegExp regExp = RegExp(
|
||||
r'^[A-Z0-9]+$',
|
||||
caseSensitive: false,
|
||||
multiLine: false,
|
||||
);
|
||||
|
||||
if (regExp.hasMatch(_pin) == true && _pin.length == _pinLenght) {
|
||||
} else {
|
||||
return 'false';
|
||||
}
|
||||
if (derivation != -1) {
|
||||
try {
|
||||
final _wallet = HdWallet.fromDewif(_dewif, _pin);
|
||||
pubkey.text = _wallet.getPubkey(derivation);
|
||||
log.d(pubkey.text);
|
||||
notifyListeners();
|
||||
|
||||
return pubkey.text;
|
||||
} catch (e) {
|
||||
log.w('Bad PIN code !\n' + e);
|
||||
notifyListeners();
|
||||
|
||||
return 'false';
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
pubkey.text = CesiumWallet.fromDewif(_dewif, _pin).pubkey;
|
||||
notifyListeners();
|
||||
return pubkey.text;
|
||||
} catch (e) {
|
||||
log.w('Bad PIN code !\n' + e);
|
||||
notifyListeners();
|
||||
|
||||
return 'false';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String readLocalWallet(
|
||||
context, WalletData _wallet, String _pin, int _pinLenght) {
|
||||
Future<String> readLocalWallet(
|
||||
context, WalletData _wallet, String _pin, int _pinLenght) async {
|
||||
isWalletUnlock = false;
|
||||
try {
|
||||
String _localDewif = chestBox.get(_wallet.chest).dewif;
|
||||
String _localPubkey;
|
||||
|
||||
if ((_localPubkey = _getPubkeyFromDewif(
|
||||
_localDewif, _pin, _pinLenght, _wallet.derivation)) !=
|
||||
'false') {
|
||||
pubkey.text = _localPubkey;
|
||||
final _pubkey = await compute(
|
||||
_getPubkeyFromDewif,
|
||||
GetPubkeyFromDewifArgs(
|
||||
_localDewif, _pin, _pinLenght, _wallet.derivation));
|
||||
|
||||
if (_pubkey != 'false') {
|
||||
pubkey.text = _pubkey;
|
||||
isWalletUnlock = true;
|
||||
log.d(pubkey.text);
|
||||
return _localDewif;
|
||||
|
@ -239,3 +202,48 @@ class WalletOptionsProvider with ChangeNotifier {
|
|||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
String _getPubkeyFromDewif(GetPubkeyFromDewifArgs parseArgs) {
|
||||
String pubkey;
|
||||
RegExp regExp = RegExp(
|
||||
r'^[A-Z0-9]+$',
|
||||
caseSensitive: false,
|
||||
multiLine: false,
|
||||
);
|
||||
|
||||
if (regExp.hasMatch(parseArgs.pin) == true &&
|
||||
parseArgs.pin.length == parseArgs.pinLenght) {
|
||||
} else {
|
||||
return 'false';
|
||||
}
|
||||
if (parseArgs.derivation != -1) {
|
||||
try {
|
||||
final _wallet = HdWallet.fromDewif(parseArgs.dewif, parseArgs.pin);
|
||||
pubkey = _wallet.getPubkey(parseArgs.derivation);
|
||||
log.d(pubkey);
|
||||
|
||||
return pubkey;
|
||||
} catch (e) {
|
||||
log.w('Bad PIN code !\n' + e);
|
||||
|
||||
return 'false';
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
pubkey = CesiumWallet.fromDewif(parseArgs.dewif, parseArgs.pin).pubkey;
|
||||
return pubkey;
|
||||
} catch (e) {
|
||||
log.w('Bad PIN code !\n' + e);
|
||||
|
||||
return 'false';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class GetPubkeyFromDewifArgs {
|
||||
final String dewif;
|
||||
final String pin;
|
||||
final int pinLenght;
|
||||
final int derivation;
|
||||
GetPubkeyFromDewifArgs(this.dewif, this.pin, this.pinLenght, this.derivation);
|
||||
}
|
||||
|
|
|
@ -198,7 +198,7 @@ class UnlockingWallet extends StatelessWidget {
|
|||
onCompleted: (_pin) async {
|
||||
log.d("Completed");
|
||||
_myWalletProvider.pinCode = _pin;
|
||||
final String resultWallet = _walletOptions.readLocalWallet(
|
||||
final String resultWallet = await _walletOptions.readLocalWallet(
|
||||
context, wallet, _pin.toUpperCase(), _pinLenght);
|
||||
// _myWalletProvider.pinCode = _pin.toUpperCase();
|
||||
_myWalletProvider.pinLenght = _pinLenght;
|
||||
|
|
Loading…
Reference in New Issue